import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	auto nq = readln.chomp.split.map!(to!int);
  BinaryHeap!(Array!(int[]), "a[0] == b[0] ? a[1] > b[1] : a[0] < b[0]") q;
  auto num = new int[](nq[0]+1);
  foreach (i; 1..nq[0]+1) {
    int a[2];
    a[0] = 0;
    a[1] = i;
    q.insert(a.dup);
  }

  foreach (_; 0..nq[1]) {
    auto x = readln.chomp.split.map!(to!int);
    num[x[0]] += x[1];
    int a[2];
    a[0] = num[x[0]];
    a[1] = x[0];
    q.insert(a.dup);
    
    while (!q.empty) {
      a = q.front;
      if (a[0] == num[a[1]]) {
        writeln(a[1], " ", a[0]);
        stdin.flush;
        break;
      }
      q.removeFront;
    }
  }
}