啥也不去想,写就完事了。。
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e4 + 5;
int arr[N];
int main() {
int L,M;
cin >> L >> M;
int ans = 0,x,y;
for (int i = 1;i <= M;i++) {
cin >> x >> y;
for (int j = x;j <= y;j++) {
arr[j] = 1;
}
}
for (int i = 0;i <= L;i++) {
if (!arr[i]) ans++;
}
cout << ans << endl;
return 0;
}