int tot; int b; int i; int ans=0; int q,p; int a[10005]; cin>>tot>>b; for(i=0;i<tot;i++){ a[i]=i; } while(b--){ cin>>q>>p; for(i=q;i<=p;i++){ a[i]=-1; } } for(i=0;i<=tot;i++){ if(a[i]>=0){ ans++; } } cout<<ans; return 0;
}