#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

pair<int, int> heap[1024 * 1024];
int idx[1024];

bool cmp(pair<int, int> lhs, pair<int, int> rhs){
  if(lhs.second != rhs.second) return lhs.second < rhs.second;
  return lhs.first > rhs.first;
}

int main(){
  const int n = getInt();
  const int q = getInt();

  REP(i,n) heap[i].first = idx[i] = i;

  REP(i,q){
    const int a = getInt() - 1;
    const int v = getInt();

    int pos = idx[a];
    heap[pos].second += v;

    if(v > 0){
      while(pos > 0){
        const int parent = (pos - 1) / 2;
        if(!cmp(heap[pos], heap[parent])){
          swap(heap[pos], heap[parent]);
          idx[heap[pos].first] = pos;
          idx[heap[parent].first] = parent;
          pos = parent;
        }else{
          break;
        }
      }
    }else{
      while(pos * 2 + 1 < n){
        vector<int> cand;
        bool change = false;
        if(pos * 2 + 1 < n) cand.push_back(pos * 2 + 1);
        if(pos * 2 + 2 < n) cand.push_back(pos * 2 + 2);

        if(cand.size() == 2 && cmp(heap[cand[0]], heap[cand[1]]))
          swap(cand[0], cand[1]);

        REP(i,cand.size()){
          const int next = cand[i];
          if(cmp(heap[pos], heap[next])){
            swap(heap[pos], heap[next]);
            idx[heap[pos].first] = pos;
            idx[heap[next].first] = next;
            pos = next;
            change = true;
            break;
          }
        }
        if(!change) break;
      }
    }

    /*
    REP(i,n) printf("%d ", idx[i]); puts("");
    int b = 0;
    REP(i,n){
      printf("(%d, %d)", heap[i].first, heap[i].second);
      if(i == b){ puts(""); b = (b + 2) * 2 - 2; }
    }
    */

    printf("%d %d\n", heap[0].first + 1, heap[0].second);
  }

  return 0;
}