#include<cstdio>
#include<map>
#include<queue>
using namespace std;

typedef pair<int,int> P;
int n,q,a,v,f[1000001]={0};

int main(){
  scanf("%d%d",&n,&q);
  priority_queue<P> p; p.push(P(0,-1));
  for(int i=0;i<q;++i){
    scanf("%d%d",&a,&v);
    f[a]+=v; p.push(P(f[a],-a));
    for(;;){
      a=-p.top().second; v=p.top().first;
      if(v==f[a]){ printf("%d %d\n",a,v); break; }
      p.pop();
    }
  }
}