import qualified Data.List as List
import qualified Data.Char as Char
import qualified Data.Maybe as Maybe

main :: IO ()
main = getContents >>=
  print . (\(n:_:dislike_digits) -> Maybe.maybe 0 id . List.find (null . List.intersect dislike_digits . map Char.digitToInt . show) $ iterate succ n) . map (read :: String -> Int) . words