#include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

long long mx[21][1 << 21];

int main() {
  int n, q;
  cin >> n >> q;
  rep (i, q) {
    int a, v;
    cin >> a >> v;
    mx[0][a] += v;
    rep (j, 20) mx[j + 1][a >> (j + 1)]  = max(mx[j][a >> j], mx[j][a >> j ^ 1]);
    int r = 0;
    rep (j, 20) {
      if (mx[19 - j][2 * r] >= mx[19 - j][2 * r + 1]) r *= 2;
      else r = 2 * r + 1;
    }
    cout << r << " " << mx[20][0] << endl;
  }
  return 0;
}