#include <iostream>
#include <queue>
using namespace std;
typedef pair<int,int> P;
int a[1000001] = {0};
int main(){
  priority_queue<P>que;
  int n,q;
  cin >> n >> q;
  que.push(P(0,0));
  for(int i = 0 ; i < q ; i++ ){
    int num,fish;
    cin >> num >> fish;
    a[num] += fish;
    que.push(P(a[num],-num));
    P top = que.top();
    while( top.first != a[-top.second]  ){
      que.pop();
      top = que.top();
    }
    cout << -top.second << " " << top.first << endl;
  } 
}