import Control.Applicative
import Control.Monad
import Data.List

ds2int :: [Int] -> Int
ds2int = read . concatMap show

main :: IO ()
main = do
    [n, _] <- fmap read . words <$> getLine :: IO [Int]
    ds <- fmap read . words <$> getLine :: IO [Int]

    let cs = [0 .. 9] \\ ds
    let c  = head $ dropWhile (== 0) cs
    let a1 = c : replicate 4 0

    let cs' = concatMap show cs
    let f x = all (`elem` cs') (show x)
    let a2 = filter f [n .. 9999]

    if null a2
        then print $ ds2int a1
        else print $ head a2