import scala.io.StdIn.readLine

object Main {
    def main(args: Array[String]){
        val intArray= readLine.split(" ").map(_.toInt)
        println(calc(intArray))
    }

    def calc(args: Array[Int]): Int = {
        val a = args(0)
        val b = args(1)
        val c = args(2)
        val d = args(3)

        if (b <= c) return 0
        
        val e1 = List(a, c).max
        val e2 = List(b, d).min
        return e2 - e1
    }
}