import java.util.Scanner

object Main extends App {
  var sc = new Scanner(System.in)
  var a = sc.nextInt
  var b = sc.nextInt
  var c = sc.nextInt
  var d = sc.nextInt
  println(List(List(b,d).min - List(a,c).max, 0).max)
}