
main :: IO ()
main = do
    [a,b,c,d] <- getInts
    print $ solve a b c d

getInts :: IO [Int]
getInts = map read . words <$> getLine

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