#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,event;
    cin>>n>>event;
    
    std::vector<int> possessionfish(n+1, 0);
    std::vector<int>::iterator iter;
    int index, topNum;
    int fishing,num;
    cin>>num>>fishing;
    possessionfish[num]+=fishing;
    cout<<num<<" "<<fishing<<endl;
    topNum = num;
    
    for(event-=1;event>0;--event){
        cin>>num>>fishing;
        possessionfish[num]+=fishing;
        if(fishing > 0){
            if(possessionfish[num] > possessionfish[topNum])topNum = num;
        }else{
            if(topNum == num){
                iter = std::max_element(possessionfish.begin(), possessionfish.end());
                index = std::distance(possessionfish.begin(), iter);
                topNum = index;
            }
        }
        cout<<topNum<<" "<<possessionfish[topNum]<<endl;
    }
}

