import Control.Monad
import Data.List
getIs = map (read :: String -> Int) . words <$> getLine
main = do
    [_,time] <- getIs
    inps <- replicateM time getIs
    let a = sortOn last inps
    let b = sortOn head a
    print b    
    