import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Char (intToDigit)

main :: IO ()
main = do
  [n, k] <- getl $ wrds toInt
  solve n <$> getl (wrds toInt) >>= print

solve :: Int -> [Int] -> Int
solve n xs = f n
  where
    ls = map intToDigit xs
    f x
      | null (intersect (show x) ls) = x
      | otherwise = f (x+1)

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine
