import Data.List

isFavoriteNumber :: Int -> [Int] -> Bool
isFavoriteNumber x ds =
  all (\d -> not(elem (head $ show d) strX)) ds
  where
    strX = show x

main = do
  [n, k] <- map	read . words <$> getLine
  ds <-	map (read :: String -> Int) . words <$> getLine
  putStrLn $ show $ head $ filter (\x -> isFavoriteNumber x ds) [n..]