#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;
 
priority_queue<pair<int, int> > q;
int n, m, d[1000001], a, b;
 
main(){
  scanf("%d%d", &n, &m);
  q.push(make_pair(0, -1));
  for(int i=0;i<m;i++){
    scanf("%d%d", &a, &b);
    d[a] += b;
    q.push(make_pair(d[a], -a));
    while(1){
      pair<int, int> p = q.top();
      if(p.first == d[-p.second]){
        printf("%d %d\n", -p.second, p.first);
        break;
      }
      q.pop();
    }
  }
}