#include <iostream>
#include <queue>
using namespace std;
typedef pair<int,int> P;
const int MAX = 1e6;

int main(){
  int n,q,a[MAX+1]={0},x,y;
  priority_queue<P> Q;

  cin >> n >> q;
  while(q--){
    cin >> x >> y;
    if(a[x] != 0) Q.pop();
    a[x] += y;
    Q.push(P(a[x],-x));
    cout << -Q.top().second << ' ' << Q.top().first << endl;
  }

  return 0;
}