import Data.List
import Data.Char
import Data.Maybe

main = print . maybe 0 id . (\(n:_:ds) -> find (null . intersect ds . map digitToInt . show) $ iterate succ n) . map (read :: String -> Int) . words =<< getContents
