#include<iostream>
using namespace std;
int a[1145141];
int main() {
	int n, q; cin >> n >> q;
	for (int i = 1; i <= n; i++)a[i] = 0;
	int p = 0, num = 0;
	for (int i = 0; i < q; i++){
		int b, c; cin >> b >> c;
		a[b] += c;
		if (num < a[b]) { p = b; num = a[b]; }
		else if (num == a[b]&&p > b)p = b;
		cout << p << ' ' << num << endl;
	}
}