{-# OPTIONS_GHC -O3 -fexpose-all-unfoldings -fdicts-cheap -fdicts-cheap #-}

import Data.Array.IO
import Data.List (minimumBy)
import Data.Ord (comparing)

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

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

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

judge :: (Int,Int) -> (Int,Int) -> IOArray 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
       return ((minimumBy (comparing snd) 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 (IOArray Int Int)
  putresult arr n (0,0)