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

int t[1000001];

class Member{
public:
  int x;
  
  Member ( int x = 0): x(x){}


  bool operator < ( Member a )const{
    return ( t[x]<t[a.x] || ( t[x]==t[a.x] && x>a.x ) );
  }



};

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;
    qu.push(i);
  }
  while(q--){
    cin>>a>>b;
    t[a]+=b;
    for(int i=0;i<1000;i++){
      s=qu.top();
      qu.pop();
      qu.push(s);
    }
    s=qu.top();
    cout<<s.x<<" "<<t[s.x]<<endl;
  }
  return 0;
}