import Data.List
import Data.Char

f :: Int -> String -> Int
f a bs
    | all (\x-> elem (intToDigit x) bs) ((map digitToInt . show) a) = a
    | otherwise = f (a + 1) bs

main :: IO ()
main = do
    [n,k] <- map read . words <$> getLine
    cs <- ("0123456789" \\) . concat . words <$> getLine
    putStrLn $ show $ f n cs