object Main {
    def main(args: Array[String]) : Unit = {
        val sc = new java.util.Scanner(System.in)
        val a, b, c, d  = sc.nextInt
        println(calc(a, b, c, d))
    }
    def calc(a: Int, b: Int, c: Int, d: Int) : Int = {
        val ab = (a to b).toSet
        val cd = (c to d).toSet
        (ab & cd).size - 1 max 0
    }
}