import Control.Monad

main :: IO ()
main = do
  nq <- getLine
  let [n,q] = map strToInt $ words nq
      assocL = []
      counter = 0
  loopq counter q assocL

strToInt :: String -> Int
strToInt str = read str

loopq :: Int -> Int -> [[Int]] -> IO ()
loopq counter q assocL = do
  if counter >= q
    then return ()
    else do
      av <- getLine
      let [a,v] = map strToInt $ words av
          assocL' = update [a,v] assocL
          ans = format $ maxSearch assocL'
      putStrLn ans
      loopq (counter + 1) q assocL'

update :: [Int] -> [[Int]] -> [[Int]]
update [x,y] [] = [[x,y]]
update [x,y] ([x',y']:rest)
  | x == x' = [x,y+y']:rest
  | otherwise= [x',y']:(update [x,y] rest)

maxSearch :: [[Int]] -> [Int]
maxSearch xs = foldl1 f xs
                where f [a,b] [c,d]
                        | (b < d) || ((b == d) && (c < a)) = [c,d]
                        | otherwise = [a,b]

format :: [Int] -> String
format [a,b] = (show a) ++ " " ++ (show b)