import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [a,b,c,d] <- map (read::String->Int) . words <$> getLine
  let t = intersect [a..b] [c..d]
  print $ safelast t - safehead t
  
safehead [] = 0
safehead (x:_) = x

safelast [] = 0
safelast [x] = x
safelast (_:xs) = safelast xs