import Data.List
import qualified Data.ByteString.Char8 as B

main = breads >>= print . solve

solve :: [Int] -> Int
solve [a, b, c, d]
    | b <= c || d <= a = 0
    | otherwise = min d b - max a c

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)
