'use strict'

function main(input) {
  const inputList = input.split(' ');
  const a = Number(inputList[0])
  const b = Number(inputList[1])
  const c = Number(inputList[2])
  const d = Number(inputList[3])

  const left = Math.max(a, c)
  const right = Math.min(b, d)

  if (left > right) {
    console.log(0)
  } else {
    console.log(right-left)
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));