import Control.Monad
import Data.Char
import Data.List

m :: Char -> [Int] -> [Int]
m x use = f
    where
        x' = digitToInt x
        f = filter (>=x') use

solve :: String -> [Int] -> String -> String
solve [] _ acc = acc
solve (x:xs) use acc
    | null us =  (replicate (l+1) $ intToDigit $ minimum $ use) ++ acc
    | otherwise = solve xs use ((intToDigit $ minimum us) : acc)
    where
        us = m x use
        l = length (x:xs)

main = do
    [n, k] <- map read . words <$> getLine :: IO [Int]
    ds <- map read . words <$> getLine :: IO [Int]
    let use = filter (\i -> notElem i ds) [0..9]
    print . (read :: String -> Int) . reverse $ solve (show n) use ""