import Control.Monad
import Data.Char
import Data.List
import Data.Maybe

main = sol <$> getN <*> getD >>= print

getN = fmap read . words <$> getLine :: IO [Int]

getD = filter isDigit <$> getLine :: IO [Char]

sol (n:_) ds = fromJust $ find ok [n..]
  where
  ok = all (`notElem` ds) . show