import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val a = sc.nextInt
  val b = sc.nextInt
  val c = sc.nextInt
  val d = sc.nextInt

  val intersect = (a to b) intersect (c to d)

  val res = if(intersect.isEmpty) 0 else intersect.size - 1

  println(res)


}