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

switchs a b c d
  | b<=c = 0
  | a>=c && b<=d = b - a
  | a<c && b>d = d - c
  | b>c && a<c = b - c
  | a>=c && b > d = d - a
  | a<=c = 0