题目不难。。。但坑得是数据大小。。N 的大小越大越好。。。
#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
int gcd(int a, int b){return b == 0 ? a : gcd(a%b, a);}
const int N = 10011;
int main()
{
int L, M, a, b, c[N];
scanf("%d %d", &L, &M);
rep(i, 0, L) c[i] = 1;
while(M--)
{
scanf("%d %d", &a, &b);
rep(i, a, b) c[i] = 0;
}
c[10010] = 0;
rep(i, 0, L) c[10010] += c[i];
printf("%d\n", c[10010]);
return 0;
}