模拟。
#include <bits/stdc++.h>
using namespace std;
int main(){
int L,M,T=0;
int start[100], end[100];
bool tree[10007];
memset(tree, false, sizeof(tree));
cin>>L>>M;
for(int i=1; i<=M; i++)
{
cin>>start[i]>>end[i];
if(start[i]>end[i] || start[i]<0 || end[i]>L) goto exit;
fill(tree+start[i], tree+end[i], true);
}
for(int i=1; i<=L; i++)
{
if(tree[i]==false) T+=1;
}
cout << T;
exit:
return 0;
}