fun main(args: Array<String>) {
    val (a, b, c, d) = readLine()!!.split(" ").map { it.toInt() }
    println(Line(a, b).overlapLength(Line(c, d)))
}

class Line(private val start: Int, private val end: Int) {
    fun overlapLength(other: Line): Int {
        return max(0, min(this.end, other.end) - max(this.start, other.start))
    }
}

fun max(a: Int, b: Int): Int = if (a > b) a else b
fun min(a: Int, b: Int): Int = if (a < b) a else b