import qualified Data.IntSet as S

main :: IO ()
main = do
    [n, _] <- map read . words <$> getLine
    ds <- S.fromList . map read . words <$> getLine
    print $ solve n ds
 
solve :: Int -> S.IntSet -> Int
solve n ds = head $ filter (favo ds) [n..]

favo :: S.IntSet -> Int -> Bool
favo ds = S.null . S.intersection ds . S.fromList . map (read . pure) . show
