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

m :: Char -> [Int] -> Char
m c use
    | null f = intToDigit $ minimum use
    | otherwise = intToDigit $ minimum f
    where
        i = digitToInt c
        f = filter (i<=) use

solve :: String -> [Int] -> String -> String
solve [x] use acc = 
    let i = m x use in (i:acc)
solve (x:xs) use acc =
    let i = m x use in solve xs use (i:acc)

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]
    let res = (read :: String -> Int) $ solve (reverse $ show n) use ""
    print $ if res < n then (res*10) + (minimum use) else res