import java.util.*;
public class Main {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	int C = sc.nextInt();
	int D = sc.nextInt();
	if(B - C <= 0 || D - A <= 0){
		System.out.println(0);
	}else{
		System.out.println(Math.min(B,D) - Math.max(A,C));
	}
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	int C = sc.nextInt();
	int D = sc.nextInt();
	if(B - C <= 0 || D - A <= 0){
		System.out.println(0);
	}else{
		System.out.println(Math.min(B,D) - Math.max(A,C));
	}
	}
} Main public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	int C = sc.nextInt();
	int D = sc.nextInt();
	if(B - C <= 0 || D - A <= 0){
		System.out.println(0);
	}else{
		System.out.println(Math.min(B,D) - Math.max(A,C));
	}
	} main {
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	int C = sc.nextInt();
	int D = sc.nextInt();
	if(B - C <= 0 || D - A <= 0){
		System.out.println(0);
	}else{
		System.out.println(Math.min(B,D) - Math.max(A,C));
	}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int A = sc.nextInt(); A sc.nextInt() sc.nextInt sc int B = sc.nextInt(); B sc.nextInt() sc.nextInt sc int C = sc.nextInt(); C sc.nextInt() sc.nextInt sc int D = sc.nextInt(); D sc.nextInt() sc.nextInt sc if(B - C <= 0 || D - A <= 0){
		System.out.println(0);
	}else{
		System.out.println(Math.min(B,D) - Math.max(A,C));
	} B - C <= 0 || D - A <= 0 B - C <= 0 B - C B C 0 D - A <= 0 D - A D A 0 {
		System.out.println(0);
	} System.out.println(0) System.out.println System.out System System.out 0 {
		System.out.println(Math.min(B,D) - Math.max(A,C));
	} System.out.println(Math.min(B,D) - Math.max(A,C)) System.out.println System.out System System.out Math.min(B,D) - Math.max(A,C) Math.min(B,D) Math.min Math B D Math.max(A,C) Math.max Math A C String[] args args public class Main {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	int C = sc.nextInt();
	int D = sc.nextInt();
	if(B - C <= 0 || D - A <= 0){
		System.out.println(0);
	}else{
		System.out.println(Math.min(B,D) - Math.max(A,C));
	}
	}
} public class Main {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	int C = sc.nextInt();
	int D = sc.nextInt();
	if(B - C <= 0 || D - A <= 0){
		System.out.println(0);
	}else{
		System.out.println(Math.min(B,D) - Math.max(A,C));
	}
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	int C = sc.nextInt();
	int D = sc.nextInt();
	if(B - C <= 0 || D - A <= 0){
		System.out.println(0);
	}else{
		System.out.println(Math.min(B,D) - Math.max(A,C));
	}
	}
}
