import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  [a, b, c, d] <- map (read::String -> Int) . words <$> getLine
  print $ if b <= c || a >= d then 0 else (min b d) - (max a c)