fun main(args: Array<String>) {
    val (A, B, C, D) = readLine()!!.split(" ").map(String::toInt)
    val CD = C..D
    var sum = 0
    for (ab in A..B) {
        if (CD.contains(ab)) {
            sum++
        }
    }

    println(
        if (sum == 0) {
            0
        } else {
            --sum
        }
    )
}

