import           Data.List

main = do
    [a, b, c, d] <- map readInt . words <$> getLine
    print . seconds $ intersect [a .. b] [c .. d]

readInt :: String -> Int
readInt = read

seconds [] = 0
seconds xs = length xs - 1