{-# OPTIONS_GHC -O2 #-}

import Data.Array.IO
import Data.List (minimumBy,foldl1')
import Data.Ord (comparing)

acmArray :: IOUArray Int Int -> (Int,Int) -> IO (IOUArray Int Int)
acmArray arr (x,y) = do
  s <- readArray arr x
  writeArray arr x (s + y)
  return arr

maxsnd (a,b) (c,d)
  | b > d           = (a,b)
  | b == d && a < c = (a,b)
  | otherwise       = (c,d)

toPut (x,y) = show x ++ " " ++ show y

listToTuple :: [(Int,Int)] -> (Int,Int)
listToTuple [(x,y)] = (x,y)

judge :: (Int,Int) -> (Int,Int) -> IOUArray Int Int -> IO (Int, Int)
judge (a,b) (x,y) arr = do
  if (a /= x) && ((b > y) || (b == y && a < x)) then return (a,b)
     else do
       tes <- getAssocs arr
       let tes' = foldl1' maxsnd tes
       return (tes')

putresult arr n (a,b) = do
  s' <- getLine
  let [x,y'] = map (read :: String -> Int) $ words s'
  acmArray arr (x,y')
  y <- readArray arr x
  (a',b') <-  judge (a,b) (x,y) arr

  putStrLn $ toPut (a',b')

  if n < 2 then return ()
  else do
--    test <- getAssocs arr
--    print test
    putresult arr (n-1) (a',b')

main = do
  s <- getLine
  let [x,n] = map read $ words s
  arr <- newArray (1,x) 0 :: IO (IOUArray Int Int)
  putresult arr n (0,0)