#include<stdio.h>
#define BB 1000001

int n[BB][2]={};
int main(){


int x,y,N,Q;
int M,R,min;

scanf("%d %d",&N,&Q);

for(int i=0;i<Q;i++){
scanf("%d %d",&x,&y);


n[x][0]+=y;
if(i==0){M=x;R=y;min=x;}

if(min>x)min=x;

if(n[x][0]>R){R=n[x][0];M=x;}
else if(n[x][0]==R&&x<M){R=n[x][0];M=x;}
if(R==0)M=min;
printf("%d %d\n",M,R);
}
return 0;
}