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


int main()
{
	int n, q;
	while( cin >> n >> q ){
		vector< int > cnt( n + 1, 0 );
		priority_queue< pair< int, int > > p;
		for( int i = 0; i < q; ++i ){
			pair< int, int > a;
			cin >> a.second >> a.first;
			cnt[ a.second ] += a.first;
			a.first = cnt[ a.second ];
			a.second = -a.second;
			p.push( a );
			while( 1 ){
				pair< int, int > b;
				b = p.top();
				p.pop();
				if( b.first == cnt[ -b.second ] ){
					cout << -b.second << " " << b.first << endl;
					p.push( b );
					break;
				}
			}
		}
	}

	return 0;
}