#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

#define MAX 1000001

int t[MAX+1],u[MAX+1];

//typedef pair<int,int> P;

class PriorityQueue{
public:
  int size;
  int buffer[MAX+1];

  PriorityQueue(){size=0;}
  void insert(int x){
    size++;
    buffer[size]=x;
    u[x]=size;
    upHeap(size);
  }

  int get(){
    int v=buffer[1];
    buffer[1]=buffer[size];
    u[buffer[size]]=1;
    size--;
    downHeap(1);
    return v;
  }


  void upHeap(int cursor){
    int parent;
    while(1){
      parent = cursor/2;
      if(parent<1)break;
      if(t[buffer[parent]]<t[buffer[cursor]]||
	 ( t[ buffer[parent] ]==t[ buffer[cursor] ]&&buffer[parent]>buffer[cursor])){
	swap(buffer[parent],buffer[cursor]);
	swap(u[buffer[parent]],u[buffer[cursor]]);
      }else break;
      cursor = parent;
    }
  }    
  void downHeap(int cursor){
    int child;
    while(1){
      if(cursor>size/2)break;
      child=cursor*2;//leftchild
      if(t[child<size&&buffer[child]]<t[buffer[child+1]])child++;
      if(t[ buffer[cursor] ]<t[ buffer[child] ]||
	 ( t[ buffer[cursor] ]==t[ buffer[child] ]&&buffer[cursor]>buffer[child])){

	swap( buffer[cursor] , buffer[child] );
	swap(u[buffer[cursor]],u[buffer[child]]);

      }else break;
      cursor=child;
    }
  }
};
  
int main(){

  PriorityQueue PQ = PriorityQueue();
  int x,y,n,q,out,tmp;
  string command;
  
  cin>>n>>q;
  for(int i=1;i<=n;i++){
    t[i]=0;
    PQ.insert(i);
  }
  while(q--){
    cin>>x>>y;
    t[x]+=y;
    

    PQ.buffer[u[x]]=PQ.buffer[PQ.size];

    u[PQ.buffer[PQ.size]]=u[x];

    PQ.size--;
    PQ.downHeap(u[x]);
    PQ.insert(x);
    
    
    
    
    out=PQ.get();
    cout<<out<<" "<<t[out]<<endl;
    PQ.insert(out);

  }
  return 0;
}