main = do
  xs <- map read . words <$> getLine
  print $ solve2 xs
solve2 (a : b : c : d : _)
    | b_c <= 0 || a_d >= 0 = 0
    | a_c <= 0 && b_d >= 0 = d - c
    | a_c >= 0 && b_d <= 0 = b - a
    | a_c >= 0 && b_d >= 0 = d - a
    | a_c <= 0 && b_d <= 0 = b - c
  where
    a_c = a - c
    b_d = b - d
    b_c = b - c
    a_d = a - d
