#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; }

template<typename Value>
struct BinaryHeap {
	static const int MAX_N = 2000010;
	vector<Value> heap;
	int sz;
	BinaryHeap() :heap(MAX_N), sz(0) {};
	void push(Value x) {
		int v = sz++;
		while (v > 0) {
			int p = (v - 1) / 2;
			if (heap[p] >= x)break;
			heap[v] = heap[p];
			v = p;
		}
		heap[v] = x;
	}
	const Value pop() {
		Value ret = heap[0];
		Value back = heap[--sz];
		int v = 0;
		while (v * 2 + 1 < sz) {
			// l ??¨ r ??????????°???????????????¨???????????????
			int l = v * 2 + 1, r = v * 2 + 2;
			int u = (r >= sz || heap[l] > heap[r]) ? l : r;
			// ???????????¢???????????????
			if (heap[u] <= back)break;
			heap[v] = heap[u];
			v = u;
		}
		heap[v] = back;
		return ret;
	}
	const Value top() {
		return heap[0];
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; scanf("%d%d", &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;
	BinaryHeap<T> pq;
	rep(i, 0, n)pq.push(T(0, -i));
	vector<int> point(n);
	rep(i, 0, q) {
		point[a[i]] += v[i];
		pq.push(T(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.push(T(p, u));
			break;
		}
	}
	return 0;
}