import           Control.Applicative
import           Control.Monad

main :: IO ()
main = do
  [as, ag, bs, bg] <- map read . words <$> getLine

  print $ f as ag bs bg

f as ag bs bg | ag < bs || bg < as = 0
              | otherwise          = min ag bg - max as bs