#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	long long n,m;

	cin >> n >> m;

	long long a[1000000],b[1000000],co[1000000],kk[1000000],s[1000000];
	for (long i = 0; i < m; i++)
	{
		kk[i] = 0;
		s[i] = 0;
	}

	for(long long j = 0; j < n; j++)
	{
		co[j] = 0;
	}

	for (long long i = 0; i < m; i++)
	{
		cin >> a[i] >> b[i];
	}

	for (long long i = 0; i < m; i++)
	{
		co[a[i] - 1] += b[i];

		for (long long j = 0; j < n; j++)
		{
			if (kk[i] < co[j])
			{
				kk[i] = 0;
				kk[i] = co[j];
				s[i] = 0;
				s[i] = j + 1;
			}

		}

		cout << s[i] << " " << kk[i] << endl;

		s[i] = 0;
		kk[i] = 0;
	}
}

