#include <cstdio>
#include <utility>
#include <queue>
using namespace std;

typedef pair<int,int> pii;

int c[1000001];

int main(){
	int n, q, a, v;
	scanf("%d%d", &n, &q);
	priority_queue<pii> pq;
	pq.push(pii(0, -1));

	for(int i = 0; i < q; ++i){
		scanf("%d%d", &a, &v);
		c[a] += v;
		pq.push(pii(c[a], -a));

		while(1){
			int x = -pq.top().second;
			int y = pq.top().first;
			if(c[x] == y){
				printf("%d %d\n", x, y);
				break;
			}
			pq.pop();
		}
	}
}