import Control.Monad

matchAll :: String -> [String] -> Bool
matchAll _ [] = False
matchAll snum (x:xs)
   | match snum x = True
   | otherwise    = matchAll snum xs

match :: String -> String -> Bool
match [] _ = False
match snum@(_:xs) xa
   | take len snum == xa = True
   | otherwise          = match xs xa
   where len = length xa 

answer :: Int -> [String] -> Int
answer n d
  | matchAll (show n) d = answer (n+1) d
  | otherwise           = n

main = do
   [n,k] <- map (read :: String -> Int) . words <$> getLine
   d <- words <$> getLine
   putStrLn . show $ answer n d