object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datA, datB, datC, datD) = readLine.split(" ").map(_.toInt)
    val onTime = math.max(datA, datC)
    val offTime = math.min(datB, datD)
    val ans = if (offTime < onTime) 0
    else offTime - onTime
    println(ans)
  }
}
