#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

#define reps(i,j,k) for(int i = j;i < k;i++)
#define rep(i,j) reps(i,0,j)
typedef pair < int,int > Pii;
int fish[1000001];
int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	priority_queue < Pii > PQ[2];
	rep(i,q){
		int a,v;
		scanf("%d%d",&a,&v);
		fish[a] += v;
		PQ[i%2].push(Pii(fish[a],-a));
		while( !PQ[i%2].empty() ){
			Pii p = PQ[i%2].top();PQ[i%2].pop();
			if(p.second != -a){
				PQ[1-i%2].push(p);
			}
			else{
				PQ[1-i%2].push(Pii(fish[a],-a));
			}
		}
		Pii p = PQ[1-i%2].top();PQ[1-i%2].pop();
		printf("%d %d\n",-p.second,p.first);
		PQ[1-i%2].push(p);
	}
	return 0;
}