object Main extends App {
  val input = io.Source.stdin.getLines.toSeq.head.split(' ').map(_.toInt).toArray
  val A = input(0)
  val B = input(1)
  val C = input(2)
  val D = input(3)
  private def eval():Int={
    if( B <= C ) return 0
    if( D <= A ) return 0
    
    val s = input.sorted
    return s(2) - s(1)
    //A C B D
    //if( A<=C && C<=B && B<=D ) return B-C
    //C A D B
    //if( C<=A && A<=D && D<=B ) return D-A
    //A C D B
    
    //C A B D
  } 
  println(eval())
}
