#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int MAX_N = 1e5 + 10;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    priority_queue<pair<int, int>> result;
    vector<int> cnt(n + 1, 0);
    vector<pair<int, int>> ans;
    for(int i = 0; i < q; i++)
    {
        int a, v; cin >> a >> v;
        cnt[a] += v;
        result.push(make_pair(cnt[a], -a));
        while(not result.empty())
        {
            pair<int, int> p = result.top();
            if(p.first == cnt[-p.second])
            {
                ans.push_back(make_pair(-p.second, p.first));
                break;
            }
            result.pop();
        }
    }
    for(int i = 0; i < ans.size(); i++) cout << ans[i].first << " " << ans[i].second << endl;
    return 0;
}


