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

main = sol <$> get <*> get >>= print

get = fmap read . words <$> getLine

sol (n:_) ds = l2i $ rs' ++ ss' ++ qs'
  where
  cs = [0..9] \\ ds
  (c0,c1) = (minimum cs,maximum cs)
  (ps,qs) = break (>c1) . reverse $ unfoldr upd n
  upd n = if n==0 then Nothing else Just (n `mod` 10,n `div` 10)
  qs' = replicate (length qs) c0
  ps' = fnd <$> ps
  fnd m = fromJust $ find (>=m) cs
  (rs,ss) = (\(q,p) -> (reverse p,reverse q)) . break (<c1) $ reverse ps'
  ss' 
    | null qs   = ss
    | otherwise = replicate (length ss) c0

  rs'
    | null qs   = rs
    | null ss   = rs
    | null rs   = [fnd 1]
    | otherwise = init rs ++ [fnd (1 + last rs)]
  l2i = foldl1' (\a b -> a*10+b)