import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.List

solve :: Int -> Int -> Int -> Int -> Int
solve a b c d = max (ed - st) 0
    where
        st = max a c
        ed = min b d


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