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 <- concat . words <$> getLine
    putStrLn $ f n ("0123456789" \\ ds)