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

sol (n:_) ds = fromJust $ find (null . intersect ds . show) [n..]