#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
 
using namespace std;
 
priority_queue<pair<int, int> > q;
map<int, int> d;
int n, m;
 
main(){
  cin >> n >> m;
  for(int i=0;i<n;i++) q.push(make_pair(0, -n));
  for(int i=0;i<m;i++){
    int a, b;
    cin >> 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]){
        cout << -p.second << ' ' << p.first << endl;
        break;
      }
      q.pop();
    }
  }
}