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

solve :: Int -> [Int] -> Int
solve n ds
    | (length $ ns \\ ds) == length ns = n
    | otherwise = solve (n+1) ds
        where
            ns = map digitToInt $ (show n)

main = do
    [n, _] <- map read . words <$> getLine :: IO [Int]
    ds <- map read . words <$> getLine :: IO [Int]
    print $ solve n ds
