#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int main(){
  priority_queue<pair<int,int> > p_q;
  int n,q;
  vector<int> mem;
  cin >> n >> q;
  mem.resize(n+1,0);
  p_q.push(make_pair(0,-1));
  for(int i=0,a,v;i<q;i++){
    cin >> a >> v;
    mem[a] += v;
    p_q.push(make_pair(mem[a],-a));
    while(!p_q.empty()){
      int pf = p_q.top().first , ps = p_q.top().second;
      if(pf == mem[-ps]){
        cout << -ps << " " << pf << endl;
        break;
      }
      p_q.pop();
    }
  }
}