#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <time.h>
#include <cstdio>
#include <queue>
using namespace std;


int memo[1000100];

int main(){
	int n,q;
	cin >> n >> q;
	priority_queue< pair<int,int> , vector< pair<int,int> > , greater< pair<int,int> > > Q;
	pair<int,int> ans(1e9,1e9);
	for(int i = 0 ; i < q ; i++){
		int a,b;
		scanf("%d%d",&a,&b);
		memo[a] += b;
		Q.push(make_pair(-memo[a],a));
		while(-Q.top().first != memo[Q.top().second] ) Q.pop();
		printf("%d %d\n",Q.top().second,-Q.top().first);
	}
}