#include<iostream>
#include<string>
using namespace std;
int n,q,best=0,second=0,a,b,c[1000000]={0};
int main(){
	cin>>n>>q;
	for(int i=0;i<q;i++){
		cin>>a>>b;
		c[a]+=b;
		if(c[best]<c[second]){
			int tmp=best;
			best=second;
			second=tmp;
		}
		else if(c[best]==c[second]&&best>second){
			int tmp=best;
			best=second;
			second=tmp;
		}
		else if(c[a]>c[best]){
			int tmp=best;
			best=a;
			second=tmp;
		}
		else if(c[a]>c[second])
			second=a;
		cout<<best<<" "<<c[best]<<endl;
	}
    return 0;
}
 