object Main extends App {
  val Array(a, b, c, d) = readLine.split(" ").map(_.toInt)
  
  val startMax = math.max(a,c)
  val endMin = math.min(b,d)
  
  val term = endMin - startMax
  println(math.max(term, 0))
}