#include<bits/stdc++.h>
using namespace std;
 
int main(){
	map<int,int>s;
	int a,b;
	cin>>a>>b;
	a=a;
	int c,d;
	cin>>c>>d;
	s.insert(pair<int,int>(c,d));
	int n=c;
	cout<<c<<" "<<d<<endl;
	for(int e=0;e<b-1;e++){
		int f,g;
		cin>>f>>g;
		s[f];
		s[f]+=g;
		if(s[n]>s[f]){cout<<n<<" "<<s[n]<<endl;}
		else if(s[n]<s[f]){n=f;cout<<n<<" "<<s[n]<<endl;}
		else {
			if(n>f)cout<<f<<" "<<s[n]<<endl;
			else cout<<n<<" "<<s[n]<<endl;
			}
		}
	}