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

#define MAX_N 100000000

priority_queue<pair<int, int>> Q;
int d[MAX_N], n, s, x[MAX_N], y[MAX_N];

int main() {
	cin >> n >> s;
	Q.push(make_pair(0, -1000000000));
	for (int i = 0; i < s; i++) {
		cin >> x[i] >> y[i];
		d[x[i]] += y[i];
		Q.push(make_pair(d[x[i]], -x[i]));
		while (true) {
			pair<int, int>p = Q.top();
			if (p.first == d[-p.second]) {
				cout << -p.second << ' ' << p.first << endl; break;
			}
			Q.pop();
		}
	}
}