import java.util.Scanner;

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

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