#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


int cnt[1000001];

int main()
{
	int n, q;
	priority_queue<P> que;
	
	que.push(P(0, -1));
	fill(cnt, cnt+1000001, 0);
	cin >> n >> q;
	
	REP(q)
	{
		int a, v;
		cin >> a >> v;
		cnt[a] += v;
		que.push(P(cnt[a], -a));
		while (true)
		{
			P res = que.top();
			if (res.first == cnt[-res.second])
			{
				cout << -res.second << " " << res.first << endl;
				break;
			}
			que.pop();
		}
	}
	
	return 0;
}



double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}