import Control.Monad
import Data.Function
import Data.List
import Data.Ord
import Data.IORef
import Data.Array.IO
import Data.Array.MArray

giveNumber :: [(Int, (Int, Int))] -> [(Int, (Int, Int))]
giveNumber = zipWith (\x (i, (p, y)) -> (i, (p, x))) [1..]

fillDigit6 :: Int -> String
fillDigit6 n = let s = show n in replicate (6 - length s) '0' ++ s

toId :: (Int, Int) -> String
toId (p, x) = fillDigit6 p ++ fillDigit6 x

main = do
    [n, m] <- map read . words <$> getLine
    ds <- replicateM m $ map (read :: String -> Int) . words <$> getLine
    ctr <- newIORef 1 :: IO (IORef Int)
    arr <- newArray (1, n) [] :: IO (IOArray Int [(Int, (Int, Int))])
    forM_ ds $ \[p, y] -> readIORef ctr >>= \i -> readArray arr p >>= writeArray arr p . ((i, (p, y)):)
    numbered <- mapArray (zipWith (\x (i, (p, y)) -> (i, (p, x))) [1..] . sortBy (comparing (snd . snd))) arr
    getElems numbered >>= mapM_ putStrLn . map (toId . snd) . sort . concat
    return ()