import Data.List

main :: IO ()
main = do
    [n,_] <- map read . words <$> getLine :: IO [Int]
    ds <- map head . words <$> getLine
    print $ head $ filter (\x -> length (show x \\ ds) == length (show n)) [n..10000]
