import scala.io.StdIn

object Main extends App {
  val Array(a, b, c, d) = StdIn.readLine.split(" ").map(_.toInt)

  val start = math.max(a, c)
  val end = math.min(b, d)
  val ans = math.max(end - start, 0)

  println(ans)
}