object Main extends App {
	val temp = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	val A = temp(0)
	val B = temp(1)
	val C = temp(2)
	val D = temp(3)

	def max(x: Int, y: Int): Int = {
		if(x < y) return y
		else x
	}

	def min(x: Int, y: Int): Int = {
		if(x < y) return x
		else y
	}

	val re = min(B,D) - max(A,C)

	if(re<0) println(0)
	else println(re)
}
