import Data.Map (Map)
import qualified Data.Map as Map
import Control.Applicative
import Control.Monad

addDict map (fn:sn:_) = 
    Map.insertWithKey (\k x y -> x + y)  fn sn map

getHeighest [x] = x
getHeighest (x:xs) =
    let h = getHeighest xs
    in 
        if((snd x) > (snd h) || ((snd x) == (snd h) && (fst x) < (fst h)) )
            then x 
            else h

inputLines n limit acc = 
    let 
        f n limit l 
            -- | n < limit - 1 = do
            --     let t = getHeighest . Map.toList $ l
            --     putStrLn $ (show $ fst t) ++ " " ++ (show $ snd t)
            --     inputLines (n + 1) limit l
            | n < limit = do
                let t = getHeighest . Map.toList $ l

                putStrLn $ (show $ fst t) ++ " " ++ (show $ snd t)

                if(n < limit - 1)
                     then inputLines (n + 1) limit l
                     else return ()
            | otherwise = return ()
    in
        do
            s <- map (read::String -> Int) . words <$> getLine
            f n limit (addDict acc s)

            return ()

main = do
    [users, events] <- map (read::String -> Int) . words <$> getLine
    inputLines 0 events (Map.empty)

