main :: IO ()
main = do
  [a, b, c, d] <- map read . words <$> getLine :: IO [Int]
  if a < c && d < b then print (d - c) else if ((d - a) - (c - a) - (d - b)) < 0 then print 0 else print ((d - a) - (c - a) - (d - b))
