import Data.Char (digitToInt)
import qualified Data.Set as S

toDigits :: (Integral a, Show a) => a -> S.Set Int
toDigits = S.fromList . fmap digitToInt . show

compute :: (Integral a, Show a) => a -> S.Set Int -> a
compute n ds
    | S.null $ S.intersection (toDigits n) ds = n
    | otherwise = compute (n + 1) ds

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