import java.util.Scanner;
public class P1047校门外的树 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt()+1; //从0开始所以+1
int[] arr = new int[m];
int n = scanner.nextInt(); //区域个数
for(int i=0;i<n;i++) {
int q = scanner.nextInt(); //起点
int w = scanner.nextInt(); //终点
for(int j=q;j<=w;j++) { //区域间的标记为1,最后1的个数就是移走的数量
arr[j] = 1; //标记为1;
}
}
int count = 0; //遍历移走的数量
for(int i=0;i<arr.length;i++) {
if(arr[i] == 1) { //
count++;
}
}
System.out.println(m-count); //总数减去移走的数量
}
}
//总结,把区域间的数遍历为1,然后计数,最后总数-计数
