#include <cstdio>
#include <utility>

static const size_t n_max = 1000000;
static int cs[n_max];
static size_t heap[n_max], paeh[n_max];

static bool lt(size_t k, size_t l) {
  auto i = heap[k], j = heap[l];
  return cs[i] > cs[j] || (cs[i] == cs[j] && i < j);
}

static void swap(size_t i, size_t j) {
  std::swap(heap[i], heap[j]);
  std::swap(paeh[heap[i]], paeh[heap[j]]);
}

int main() {
  size_t n, q;
  scanf("%zu%zu", &n, &q);
  for (size_t i = 0; i < n; i++)
    heap[i] = paeh[i] = i;
  for (size_t i = 0; i < q; i++) {
    size_t a;
    int v;
    scanf("%zu%d", &a, &v);
    a--;
    cs[a] += v;
    if (v > 0)
      for (auto j = paeh[a]; j;) {
        auto k = (j-1)/2;
        if (lt(j, k)) {
          swap(j, k);
          j = k;
        } else
          break;
      }
    else {
      size_t i = paeh[a];
      for (;;) {
        size_t j = i * 2 + 1, k = i * 2 + 2, l = i;
        if (j < n && lt(j, l))
          l = j;
        if (k < n && lt(k, l))
          l = k;
        if (i == l)
          break;
        swap(i, l);
        i = l;
      }
    }
    printf("%zu %d\n", heap[0] + 1, cs[heap[0]]);
  }
}