#include <iostream>
#include <map>
#include <queue>
using namespace std;
int d[10000000]={0};
int main(){
  priority_queue< pair<int,int> >q;
  int a,b;
  pair<int,int>p;
  int n,m;
  cin >> n >> m;
  for(int i = 0 ; i < m ; i++){
    cin >> a >> b;
    d[a] += b;
    q.push(make_pair(d[a],-a));
    while(1){
      p = q.top();
      if(p.first == d[-p.second]){
	cout << -p.second << " " << p. first<< endl;
	break;
      }
      q.pop();
    }
  }
  return 0;
}