import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import qualified Data.IntMap as IM

main :: IO ()
main = do
  [n,q] <- getl $ split toInt
  solve n q IM.empty

solve :: Int -> Int -> IM.IntMap Int -> IO ()
solve n q im = do
  when (q /= 0) $ do
    [a,v] <- getl $ split toInt
    let nim = IM.insertWith (+) a v im
    printTop . findTop $ IM.assocs nim
    solve n (q - 1) nim

printTop :: (Int,Int) -> IO ()
printTop (x,y) = putStrLn $ show x ++ " " ++ show y

findTop :: [(Int,Int)] -> (Int,Int)
findTop = maximumBy (\x y -> if (snd x) == (snd y) then (fst y) `compare` (fst x) else (snd x) `compare` (snd y))

toInt :: String -> Int
toInt s = read s

split :: (String -> a) -> String -> [a]
split f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine