#include <bits/stdc++.h>
using namespace std;

class PQ_COMP{
public:
  bool operator()(const tuple<int,int,int>&q1,const tuple<int,int,int>&q2)
  {
    if(get<0>(q1) == get<0>(q2)){
      return get<1>(q1)>get<1>(q2);
    }
    else{
      return get<0>(q1)<get<0>(q2);
    }
  }
};

int main()
{
  int n,q;
  cin >> n >> q;
  vector<int>v1(n,0);
  vector<int>v2(n,0);
  priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,PQ_COMP>pq;

  for(int i=0;i<n;i++)
  {
    pq.push(make_tuple(0,i,0));
  }
  for(int i=0;i<q;i++){
    int id,num;
    cin >> id >> num;
    id--;
    v1[id]+=num;
    v2[id]+=1;
    pq.push(make_tuple(v1[id],id,v2[id]));
    while(true){
      auto buf=pq.top();
      id=get<1>(buf);
      if(get<2>(buf)!=v2[id]){
        pq.pop();
        continue;
      }
      int &o1=get<1>(buf);
      int &o2=get<0>(buf);
      cout << o1+1 << " " << o2 << endl;
      break;
    }
  }
  return 0;
}
