main = do
  [a, b, c, d] <- (map read . words) <$> getLine
  putStrLn . show $ solve a b c d

solve:: Int -> Int -> Int -> Int -> Int
solve a b c d
  | c > b = 0
  | a > d = 0
  | a < c && b > d = d - c
  | c < a && d > b = b - a
  | b > c = b - c
  | a < d = d - a
