#include <iostream>
#include <stdio.h>
using namespace std;

int mx[3000000],nm[3000000];

int main() {
    int n,q,s,k,id;
	cin >> n >> q;
	for (q;q>0;q--) {
		cin >> s >> k;
         id=1048574+s;
		 nm[id]=s; mx[id]+=k;
		 do {
			 id=(id-1)/2;
			 if (mx[id*2+1]>=mx[id*2+2]) { mx[id]=mx[id*2+1]; if (nm[id*2+1]>0) nm[id]=nm[id*2+1]; }
			 else { mx[id]=mx[id*2+2]; nm[id]=nm[id*2+2];}
		 } while (id>0);
		 cout << nm[0] << " " <<  mx[0] << endl;
	}
	return 0;
}