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

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

solve :: String -> [Int] -> String -> String
solve [] _ acc = acc
solve (x:xs) use acc
    | judge < (digitToInt x) = comp ++ [judge'] ++ acc
    | otherwise = solve xs use (judge':acc)
    where
        judge = m x use
        judge' = intToDigit judge
        l = length (x:xs)
        comp = replicate l $ if 0 `elem` use then '0' else judge'

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 ""