#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
using namespace std;
typedef pair<int,int>P;
typedef vector<P>VP;
typedef priority_queue<P,VP>PQ;
int  box[1000001];
int main(void){
	int n,q;
	int i;
	int x,y;
	PQ que;
	P pp;
	cin>>n>>q;
	for(i=1;i<=n;i++)	box[i]=0;
	for(i=0;i<q;i++){
		cin>>x>>y;
		box[x]+=y;
		que.push(MP(box[x],-1*x));
		while(1){
			pp=que.top();
			que.pop();
			if(pp.F==box[-1*pp.S])	break;
		}
		cout<<-1*pp.S<<" "<<pp.F<<endl;
		que.push(pp);
	}
	return 0;
}
		
		
		
