#include<iostream>
#include<queue>
using namespace std;

int t[1000001];

class Member{
public:
  int id,cnt;
  Member ( int id = 0,int cnt=0): id(id),cnt(cnt){}
  bool operator < ( Member a )const{
    return ( cnt<a.cnt || ( cnt==a.cnt && id>a.id ) );
  }
};

int main(){
  int n,q,a,b;
  Member s;
  priority_queue<Member> qu;
  cin>>n>>q;
  for(int i=1;i<=n;i++){
    t[i]=0;
    s.id=i;s.cnt=0;
    qu.push(s);
  }
  while(q--){
    cin>>a>>b;
    t[a]+=b;
    qu.push(Member(a,t[a]));

    while(1){
      if(qu.top().cnt == t[qu.top().id] )break;
      qu.pop();
    }
    cout<<qu.top().id<<" "<<qu.top().cnt<<endl;

  }
  return 0;
}