import Data.List

f [] bs = []
f (a:as) bs =
    if elem a bs
    then a : f as bs
    else (head (dropWhile (<=a) bs)) : zipWith (\_ _ -> head bs) as [1..]

main :: IO ()
main = do
    [n, k] <- words <$> getLine
    ds <- ("0123456789" \\) . concat . words <$> getLine
    if length n == 1
    then putStrLn $ (\[a] bs ->
        (head (dropWhile (=='0') bs)) : if a < last bs
                                        then []
                                        else [head bs]
                                        ) n ds
    else putStrLn $ f n ds