#include<iostream>
#include<vector>
#include<string>
#include<set>
using namespace std;

signed main() {
	int a, b;
	cin >> a >> b;
	int *c = new int[a] {};
	set<int>s;
	for (int d = 0; d < b; d++) {
		int e, f;
		cin >> e >> f; e--;
		c[e] += f;
		s.insert(e);
		int x = 0, y = 0;
		for (auto i = s.begin(); i != s.end(); i++) {
			if (x < c[*i]) { x = c[*i]; y = *i;}
		}
		cout << y + 1 << " " << x << endl;
	}
}