main :: IO ()
main = do
    (n:_) <- map read . words <$> getLine
    ds <- filter (/=' ') <$> getLine
    print $ calc n ds

calc :: Int -> String -> Int
calc n ds = head $ dropWhile dislike [n..]
  where
    dislike n = any (`elem` ds) (show n)