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)
  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))
    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
    }.map{x => x._1 + " " + x._2 }
    r += a(0)
  }
  println(r.mkString("\n"))
}