-- fo "http://abc042.contest.atcoder.jp/tasks/arc058_a"

import Data.List
import Control.Applicative

main = do
  p <- getContents
  let n = read $ head $ words $ head $ lines p :: Int
      k = read $ last $ words $ head $ lines p :: Int
      d  =   words $last  $ lines p -- d !! i = D_i
      pre = [n..]
      l =  n `mod` 10 
      result = ( find (\n-> ( show n) `notElem` d )  pre ) 
      result' = (\(Just x) -> x) result
  putStr $ show result'
