import scala.io.StdIn.readLine
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.HashMap

object Main extends App {
  val h = new HashMap[Int,Int]
  val r = new ArrayBuffer[String]
  val q = readLine.split(" ").map(_.toInt)
  var max = (-1,-1)
  for(i<-1 to q(1)) {
    val n = readLine.split(" ").map(_.toInt)
    if(h.contains(n(0)))
      h.update(n(0),h(n(0)) + n(1))
    else
      h += (n(0)->n(1))

    if(max._1 == n(0) && max._2 > h(n(0))) {
      val a =  h.toArray.sortWith{ (x,y) =>
        if(x._2>y._2) true else if(x._2==y._2 && x._1 < y._1) true else false
      }
      max = (a(0)._1,a(0)._2)
    } else if(max._2 < h(n(0))) {
      max = (n(0),h(n(0)))
    } else if(max._2==h(n(0)) && max._1 > n(0)) {
      max = (n(0),h(n(0)))
    }

    r += max._1 + " " + max._2
  }
  println(r.mkString("\n"))
}