import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    [n, k] <- words <$> getLine
    l <- getLine
    let likes = ['0'..'9'] \\ l
    -- 出力
    putStrLn $ solve likes n

solve :: String -> String -> String
solve _ [] = []
solve likes n = head (filter (>= (head n)) likes) : solve likes (tail n)
