private fun readInts() = readLine()!!.split(" ").map { it.toInt() }

fun main(args: Array<String>) {
    val (A, B, C, D) = readInts()

    val lateStarted = Math.max(A, C)
    val earlyEnded = Math.min(B, D)
    val time = earlyEnded - lateStarted

    println(if (0 < time) time else 0)
}