import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int l = scanner.nextInt();
int n = scanner.nextInt();
int [][] records = new int [n][2];
for(int i = 0;i<n;i++) {
records[i][0] = scanner.nextInt();
records[i][1] = scanner.nextInt();
}
Arrays.sort(records,Comparator.comparingInt(o->o[0]));
int index = -1;
int [][] temp = new int [n][2];
for(int [] rec:records) {
if(index==-1||rec[0]>temp[index][1]) {
temp[++index] = rec;
}else {
temp[index][1] = Math.max(temp[index][1], rec[1]);
}
}
int tempSum = l+1;
int [][] res = Arrays.copyOf(temp, index+1);
for(int i = 0;i<res.length;i++) {
tempSum-=(res[i][1]-res[i][0]+1);
}
System.out.println(tempSum);
}
}
1)先左端点排序
2)合并区间
3) 0-L = L+1 - (每个区间的范围+1)