#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	vector<int> a(q), v(q); rep(i, 0, q) {
		scanf("%d%d", &a[i], &v[i]);
		a[i]--;
	}
	using T = tuple<int, int>;
	priority_queue<T> pq;
	rep(i, 0, n)pq.emplace(0, -i);
	vector<int> point(n);
	rep(i, 0, q) {
		point[a[i]] += v[i];
		pq.emplace(point[a[i]], -a[i]);
		while (true) {
			int p, u; tie(p, u) = pq.top(); pq.pop();
			if (point[-u] != p)continue;
			printf("%d %d\n", -u + 1, p);
			pq.emplace(p, u);
			break;
		}
	}
	return 0;
}