#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct node {
  int i;
  int v;
};

int main() {
  int n, q;
  cin >> n >> q;

  int persons[1000001] = {};
  auto c = [](node &l, node &r) {
    return ((l.v < r.v) || ((l.v == r.v) && (l.i > r.i)));
  };
  priority_queue<node, vector<node>, decltype(c)> que(c);

  for (int i = 1; i <= n; ++i)
    que.push({i, 0});

  for (int i = 0; i < q; ++i) {
    int a, v;
    cin >> a >> v;

    persons[a] += v;
    que.push({a, persons[a]});

    while (true) {
      const node& t = que.top();
      if (persons[t.i] == t.v)
        break;
      que.pop();
    }

    cout << que.top().i << " " << que.top().v << endl;
  }
}
