import Control.Monad

data Tree = Empty | Node (Int,Int) Tree Tree

insert :: (Int,Int) -> Tree -> Tree
insert t Empty = Node t Empty Empty
insert (a,b) (Node (a',b') left right)
  | a < a'  = Node (a',b') (insert (a,b) left) right
  | a > a'  = Node (a',b') left (insert (a,b) right)
  | a == a' = Node (a,b+b') left right
  
getValue :: Int -> Tree -> Int
getValue _ Empty = 0
getValue a (Node (a',b') left right)
  | a < a'  = getValue a left
  | a > a'  = getValue a right
  | a == a' = b'

maxValue :: Tree -> (Int,Int)
maxValue Empty = (-1,-1)
maxValue (Node (a,b) left right) = (a,b) `comp` (maxValue left) `comp` (maxValue right)

comp :: (Int,Int) -> (Int,Int) -> (Int,Int)
(a,b) `comp` (c,d)
  | b > d || ((b == d) && (a < c)) = (a,b)
  | otherwise                      = (c,d)

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

main :: IO ()
main = do
  nq <- getLine
  let [n,q] = map (read :: String -> Int) (words nq)
  loopq 0 q Empty (0,0)


loopq :: Int -> Int -> Tree -> (Int,Int) -> IO ()
loopq pre_counter q pre_tree pre_ans = do
  let counter' = pre_counter + 1
  if counter' <= q
    then do
      
      av <- getLine
      let [a,v] = map (read :: String -> Int) (words av)
          tree' = insert (a,v) pre_tree
          ans = maxValue tree'



      putStrLn $ format ans
      loopq counter' q tree' ans
    else return()