import Data.Maybe
import Data.List

main = putStrLn . show . solve =<< parse

solve :: (Int, [Int]) -> Int
solve (n, ds) = fromJust $ find (canPay ds) [n..]

canPay :: [Int] -> Int -> Bool
canPay ds n = all (flip notElem ds) (nums n)

nums :: Int -> [Int]
nums n
    | n < 10 = [n]
    | otherwise = q : nums p where
          (p, q) = divMod n 10

parse :: IO (Int, [Int])
parse = do
    [n, k] <- readInts
    ds <- readInts
    return (n, ds)

readInts :: IO [Int]
readInts = map read . words <$> getLine
