#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int main(){
  priority_queue < pair<int,int> > q;
  int n,p,a,v,N[1000001]={};
  cin>>n>>p;
  for(int i=0;i<p;i++){
    cin>>a>>v;
    N[a]+=v;
    q.push( make_pair(N[a],a) );
    cout<<q.top().second<<" "<<q.top().first<<endl;
  }
  return 0;
}