#include<iostream>
#include<queue>
using namespace std;

struct Point {
  int x,y;
  bool operator < (const Point& p) const {
    if( y != p.y ) return y < p.y;
    return x > p.x;
  }
};
ostream& operator << (ostream& os,const Point& p) {
  os << p.x << " " << p.y ;
}

int main(){
  priority_queue<Point> Q;
  int n,q,a,v;
  int get[1000000]={0},_top;

  cin >>n>>q;
  for(int i=0;i<q;i++){
    cin >>a>>v;
    get[a]+=v;
    Q.push((Point){a,get[a]});
  PREV:;
    if(get[Q.top().x] != Q.top().y){
      Q.pop();
      goto PREV;
    }
    else{
    cout <<Q.top()<<endl;
    }
  }
  return 0;}
    
    