#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return b.second > a.second;
    }
    return a.first < b.first;
}

ll arr[1000010];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(6);

    int n, q;
    cin >> n >> q;

    priority_queue<pair<int, int>> que;

    for (int i = 0; i < q; ++i)
    {
        int a, v;
        cin >> a >> v;
        arr[a] += v;

        que.push(make_pair(arr[a], -a));
        while (!que.empty())
        {
            if (que.top().first == arr[-que.top().second])
            {
                cout << -que.top().second << " " << que.top().first << endl;
                break;
            }
            que.pop();
        }
    }
    return 0;
}
