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

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

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