#include<iostream>
#include<queue>
using namespace std;
class com{
    public:bool operator()(const pair<int,int>p1,const pair<int,int>p2){
        return p1.first==p2.first?p1.second>p2.second:p1.first<p2.first;
    }
};
int main(){
    int p[1000001]={0};
    int n,q,a,v;
    priority_queue<pair<int,int>,vector<pair<int,int> >,com>que;
    cin>>n>>q;
    while(q--){
        cin>>a>>v;
        p[a]+=v;
        que.push(make_pair(p[a],a));
        while(que.top().first!=p[que.top().second])que.pop();
        cout<<que.top().second<<" "<<que.top().first<<endl;
    }
}