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

struct Data{
  int x,y;

  bool operator < (const Data& data) const{
    if( y != data.y )return y < data.y;
    return x > data.x;

  }
};

int re[1000001];

int main(){

  int x, y;
  int datax, datay;

  priority_queue<Data> Q;

  cin >> x >> y;

  for(int i = 0; i < y; i++){
    // if(i != y){
      cin >> datax >> datay;
      re[datax] += datay;
      Q.push((Data){datax,re[datax]});
      // }
      while( !Q.empty() && Q.top().y != re[Q.top().x]) Q.pop();
    Data data = Q.top();
    cout << data.x << " " << data.y << endl;
  }
   

  return 0;
}