#include #include #include #include struct E{ int i,o; bool operator<(const E& e1)const{ if(i!=e1.i)return i>e1.i; return o>e1.o; } }; int main(){ std::priority_queue pq; std::map ms; int n,m; scanf("%d %d",&n,&m); for(int i=0;ie1.o){ printf("err\n"); } if(d1<2||8::iterator it=ms.begin(); while((it!=ms.end())&&((*it).first=n){ ms[e1.o]++; count++; if(count>n){ it=ms.end(); it--; (*it).second--; if((*it).second<1){ ms.erase(it); } count--; } }else{ count++; ms[e1.o]++; } } ans+=count; printf("%d\n",ans); }