C++
using namespace std;
#define MAX 10000
bool L[MAX + 1];//true代表有树,false没有树
int main() {
int l, M;
while (cin >> l >> M) {
for (int i = 0; i <= l; i++) {
L[i] = true;//初始有树
}
for (int i = 1; i <= M; i++) {
int x1, x2;
cin >> x1 >> x2;
for (int j = x1; j <= x2; j++) {
L[j] = false;
}
}
int sum = 0;
for (int i = 0; i <= l; i++) {
sum += (L[i]) ? 1 : 0;
}
cout << sum << endl;
}
return 0;
}