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] <-map reverse <$> words <$> getLine
    l <- getLine
    let likes = ['0'..'9'] \\ l
    -- 出力
    putStrLn . reverse $ solve likes n

solve :: String -> String -> String
solve _ [] = []
solve likes n
    | null m && length n == 1 = let c = if head likes == '0' then likes!!1 else '0' in head likes : [c]
    | otherwise = head m : solve likes (tail n)
    where m = filter (>= (head n)) likes
