#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
#define F first
#define S second
#define INF -(1<<29)
using namespace std;
typedef pair<int,int> P;
const int MAX_N = 1000010;
int n;
P dat[3*MAX_N-1];

bool cmp(const P& a,const P& b)
{
  if(a.F == b.F)
    return a.S > b.S;
  return a.F < b.F;
}

void init(int n_)
{
  n = 1;
  while(n < n_)n *= 2;
  for(int i=0;i<2*n-1;i++)dat[i] = P(INF,INF);
}

void update(int k,P a)
{
  k += n-1;
  dat[k] = a;
  while(k > 0)
    {
      k = (k-1)/2;
      dat[k] = max(dat[k*2+1],dat[k*2+2],cmp);
    }
}

P query(int a,int b,int k,int l,int r)
{
  if(r <= a || b <= l)return P(INF,INF);

  if(a <= l && r <= b)return dat[k];
  else
    {
      P vl = query(a,b,k*2+1,l,(l+r)/2); 
      P vr = query(a,b,k*2+2,(l+r)/2,r);
      return max(vl,vr,cmp);
    }
}

P _query(int a,int b)
{
  return query(a,b,0,0,n);
}

int main()
{
 
  /*
  P ta,tb;
  ta = P(-6,1);
  tb = P(-6,7);
  P pes = max(ta,tb,cmp);
  cout << pes.F << " " << pes.S << endl;
  */
  int N,q;
  cin >> N >> q;
  P val[N+1];
  init(N);
  vector<P> vec;
  for(int i=0;i<=N;i++)
    val[i] = P(INF,INF);

  for(int i=0;i<q;i++)
    {
      int a,v;
      cin >> a >> v;     
      if(val[a] == P(INF,INF))
	{
	  vec.push_back(P(v,a));
	  int index = vec.size()-1;
	  val[a] = P(v,index);
	  update(index,P(v,a));
	}
      else
	{
	  val[a].F += v;
	  update(val[a].S,P(val[a].F,a));
	}
      P ans = _query(0,vec.size());
      cout << ans.S << " " << ans.F << endl;
    }

  return 0;
}