#include #include using namespace std; long D; int Q; set >S; main() { cin>>D>>Q; long ans=0; for(int i=0;i>A>>B; B++; pairnow=make_pair(A,B); set >::iterator it=S.lower_bound(make_pair(A,-1)); while(it!=S.end()&&it->first<=now.second) { if(now.secondsecond)now.second=it->second; it=S.erase(it); } while(it!=S.begin()) { it--; if(now.first>it->second)break; if(now.first>it->first)now.first=it->first; it=S.erase(it); } if(ans