#include <bits/stdc++.h>

#ifdef _DEBUG
#define ASSERT(x) assert(x)
#define DLOG(x) cout << #x " " << x << endl;
#else
#define ASSERT(x)
#define DLOG(x)
#endif

using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  vector<int> people(n, 0);
  map<int, set<int>> m;
  ostringstream ss;
  for (int i = 0; i < q; ++i) {
    int a, v;
    cin >> a >> v;
    --a;
    if (people[a]) {
      auto it = m.find(people[a]);
      if (it->second.size() > 1) {
        it->second.erase(a);
      } else {
        m.erase(it);
      }
    }
    people[a] += v;
    if (people[a]) {
      m[people[a]].insert(a);
    }
    if (m.empty()) {
      ss << 1 << " " << 0;
    } else {
      auto it = m.rbegin();
      ss << (*it->second.begin() + 1) << " " << it->first;
    }
    ss << endl;
  }

  cout << ss.str();
}

