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              = 0
              | as <= bs && bg <= ag = bg - bs
              | bs <= as && as <= bs = ag - as
              | otherwise            = ag - bs