#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n, q;
    cin >> n >> q;
    priority_queue<P> que;
    que.push(P{0, 0});
    vector<int> cnt(n);
    for(int i=0; i<q; ++i) {
        int a, v;
        cin >> a >> v;
        a--;
        cnt[a] += v;
        que.push(P{cnt[a], -a});
        while(true) {
            P p = que.top();
            if(cnt[-p.second] != p.first) {
                que.pop();
            } else {
                cout << -p.second + 1 << ' ' << p.first << endl;
                break;
            }
        }
    }
}
