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

int main()
{
	int n, q, a, v, fish[1000001];
	cin >> n >> q;
	priority_queue<pair<int, int> > Q;
	Q.push(make_pair(0, -1));
	while(q--) {
		cin >> a >> v;
		fish[a] += v;
		Q.push(make_pair(fish[a], -a));
		while (Q.top().second == -a && Q.top().first > fish[a]) Q.pop();
		cout << -Q.top().second << " " << Q.top().first << endl;
	}
}