import Control.Monad readInts :: String -> [Int] readInts = map read . words getInts :: IO [Int] getInts = liftM readInts getLine main = do [x, y] <- getInts [x2, y2] <- getInts print $ if x == y && x2 == y2 && x2 < x then x + 1 else x + y - min x y