#include <iostream>
#include<map>
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

priority_queue<pair<int, int> > q;
int n, m, d[1000001], a, b;

main(){
    scanf("%d%d", &n, &m);
    q.push(make_pair(0, -1));
    for(int i=0;i<m;i++){
        scanf("%d%d", &a, &b);
        d[a] += b;
        q.push(make_pair(d[a], -a));

        pair<int, int> p = q.top();
        printf("%d %d\n", -p.second, p.first);
    }
}