import java.util.*

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