#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
typedef pair<int,int> P;
int fish[1000001];
vector<P> res;
bool cmp(pair<int,int> l,pair<int,int> r){
    if(l.second > r.second) return true;
    else if(l.second < r.second) return false;
    else{
        if(l.first < r.first) return true;
        else return false;
    }
}
int main(){
    int n,q;
    scanf("%d%d",&n,&q);
    rep(i,q){
        int a,v;
        scanf("%d%d",&a,&v);
        fish[a] += v;
        rep(j,res.size())if(res[j].first == a){remove(res.begin(),res.end(),res[j]);}
        res.push_back(P(a,fish[a]));
        sort(res.begin(),res.end(),cmp);
        P p = res[0];
        printf("%d %d\n",p.first,p.second);
    }
    return 0;
}