#include #include #include #include struct E{ int i,o; bool operator<(const E& e1)const{ if(o!=e1.o)return o>e1.o; return i>e1.i; } }; int main(){ std::priority_queue pq; std::map ms; int n,m; scanf("%d %d",&n,&m); for(int i=0;i=e1.o){ printf("err\n"); } //std::cout<::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); }