#include <iostream>
#include <cstring>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int n[1000001];

int main()
{
	memset(n,0,sizeof(n));
	int num,q;
	cin >> num >> q;

	priority_queue< pair<int,int> > p;
	rep(i,q)
	{
		int a, v;
		cin >> a >> v;
		n[a-1] += v;
		
		p.push(make_pair(n[a-1],-(a-1)));

		while(true)
		{
			int team = -p.top().second;
			if(n[team] == p.top().first)
			{
				cout << team+1 << " " << p.top().first << endl;
				break;
			}
			p.pop();
		}
	}
	
	

	return 0;
}