import Data.Char

m :: Int -> [Int] -> Int
m n xs = if foldl (||) False $ map (\i -> (chr (ord '0' + i)) `elem` (show n)) xs then m (n + 1) xs else n

main = do
  [n, k] <- map read . words <$> getLine
  nums <- map read . words <$> getLine
  putStrLn $ show $ m n nums