#include <iostream>
#include <queue>
using namespace std;

typedef pair<int, int> P;

int main(){
    int a, n, q, v, m_a = 0;
    cin >> n >> q;
    vector<int> fish(n, 0);
    priority_queue< P > pq;
    pq.push( P(1, 0) );
    for(int i = 0; i < q; i++){
        cin >> a >> v;
        fish[a] += v;
        pq.push( P(fish[a], -a) );
        while( fish[-pq.top().second] != pq.top().first ) pq.pop();
        cout << -pq.top().second << ' ' << pq.top().first << endl;
    }
    return 0;
}