import Control.Applicative

check :: Bool -> Bool -> (Integer -> Integer -> Integer -> Integer -> Integer)
check True True = \a b c d -> d - c
check True False = \a b c d -> 0
check False True = \a b c d -> b - c
check False False = \a b c d -> 0

main = do
  [a,b,c,d] <- map read . words <$> getLine
  let flag1 = b > d
  let flag2 = b > c
  let f = check flag1 flag2
  print $ f a b c d
