
import std.stdio, std.container, std.typecons;

struct User {
  int id;
  int value;
  int opCmp(ref User u) {
    if (this.value == u.value) return (u.id - this.id);
    return this.value - u.value;
  }
}

void main() {
  User[int] sum;
  int users, events;
  auto h = heapify(Array!User());
  readf("%d %d\n", &users, &events);
  foreach(t; 0..events) {
    int id, event;
    readf("%d %d\n", &id, &event);
    if (!(id in sum)) {sum[id] = User(id, 0);}
    sum[id].value += event;
    h.insert(sum[id]);
    
    while(true) {
      User u = h.front;
      if (sum[u.id].value == u.value) break;
      h.removeFront;
    }
  writeln(h.front.id, " ", h.front.value);
  }
}