#include<iostream>
#include<map>
int a[1000000];
using namespace std;
int main(){
    int n,q;
    int mx=1,my=0;
    cin>>n>>q;
    for(int i=0;i<q;i++){
        int x,y;
        cin>>x>>y;
        a[x] += y;
        if(a[x]>my){
            my = a[x];
            mx = x;
        }
        else if(a[x]==my&&x<mx){
            mx = x;

        }
        cout<<mx<<" "<<my<<endl;
    }
    return 0;
}