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

struct query {
	int a, v;

	query(int a_, int v_) { a = a_; v = v_; }

	void print() {
		cout << a << " " << v << endl;
	}

	bool operator<(const query q) const {
		if(v == q.v)
			return a > q.a;
		else
			return v < q.v;
	}
};

int main(void) {
	int n, q;
	priority_queue<query> p;
	map<int,int> m;

	cin >> n >> q;

	p.push(query(1, 0));
	m[1] = 0;
	for(int i = 0; i < q; i++) {
		map<int,int>::iterator iter;
		int a, v;
		cin >> a >> v;

		iter = m.find(a);
		if(iter != m.end())
			iter->second += v;
		else {
			m[a] = v;
			iter = m.find(a);
		}
		p.push(query(iter->first,iter->second));

		while(1) {
			query tmp(0,0);
			tmp = p.top();
			if(tmp.v != m.find(tmp.a)->second)
				p.pop();
			else {
				tmp.print();
				break;
			}
		}
	}
}