import Data.List
import Control.Monad

main :: IO ()
main = do
  [n, _] <- words <$> getLine
  d <- concat . words <$> getLine
  print $ minimum $ solve n d

solve :: String -> String -> [Int]
solve l d = do
  let n = read l :: Int
  a <- [n + i | i <- [0..9*n]]
  guard $ null $ intersect (show a) d
  return a
