
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Data.Ord
import Control.Monad


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    [n,m] <- r'
    pys <- replicateM m $ do
        [p,y] <- r'
        return (p,y)
    let numPY = zip [1..] pys :: [(Int,(Int,Int))]
    let srtdPY = sortBy (comparing snd) numPY
    let rnkdPY = rank (fst (head srtdPY), 1) srtdPY
    let finPY = map snd $ sortOn fst rnkdPY
    mapM_ (putStrLn.showCity) finPY


rank :: (Int, Int) -> [(Int,(Int,Int))] -> [(Int,(Int,Int))]
rank _ [] = []
rank (cPref, ac) ((city,(pref,year)):xs)
    | pref==cPref = (city,(pref,ac)):(rank (pref,ac+1) xs)
    | otherwise   = (city,(pref,1 )):(rank (pref, 1+1) xs)

showCity :: (Int,Int) -> String
showCity (pref,rank) =
    let pS = show pref
        rS = show rank
        pI = 6 - (length pS)
        rI = 6 - (length rS)
    in  replicate pI '0' ++ pS ++ replicate rI '0' ++ rS

