#include<iostream>
#include<map>
#include<queue>
#include<cstring>
using namespace std;

typedef pair<int,int> P;
priority_queue<P> que;
void bfs(int wa,int hu);
int res[1000002];

int main(){
	int n,q,a,v;
	cin >> n >> q;
	memset(res,0,n+2);
	for(int i=0;i<q;i++){
		cin >> a >> v;
		res[a] += v;
		bfs(res[a],-a);
	}
}

void bfs(int wa,int hu){
	que.push(P(wa,hu));
	int tmp,po;
	while(1){
		P p = que.top();
		po = p.first;
		tmp = -p.second;
		if(res[tmp] == po){
			break;
		}
		que.pop();
	}
	cout << tmp << " " << po << endl;
}