import java.util.Scanner;

public class Main {

	private static final String SHARP = "#";
	private static final String DOT = ".";

	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();
		int answer = 0;

		if (B < C || D < A) {
			answer = 0;
		} else {
			answer = Math.min(B, D) - Math.max(A, C);
		}

		System.out.println(answer);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	private static final String SHARP = "#";
	private static final String DOT = ".";

	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();
		int answer = 0;

		if (B < C || D < A) {
			answer = 0;
		} else {
			answer = Math.min(B, D) - Math.max(A, C);
		}

		System.out.println(answer);
	}
} Main private static final String SHARP = "#"; SHARP "#" private static final String DOT = "."; DOT "." 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();
		int answer = 0;

		if (B < C || D < A) {
			answer = 0;
		} else {
			answer = Math.min(B, D) - Math.max(A, C);
		}

		System.out.println(answer);
	} main {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int answer = 0;

		if (B < C || D < A) {
			answer = 0;
		} else {
			answer = Math.min(B, D) - Math.max(A, C);
		}

		System.out.println(answer);
	} 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 int answer = 0; answer 0 if (B < C || D < A) {
			answer = 0;
		} else {
			answer = Math.min(B, D) - Math.max(A, C);
		} B < C || D < A B < C B C D < A D A {
			answer = 0;
		} answer = 0 answer 0 {
			answer = Math.min(B, D) - Math.max(A, C);
		} answer = Math.min(B, D) - Math.max(A, C) answer 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 System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {

	private static final String SHARP = "#";
	private static final String DOT = ".";

	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();
		int answer = 0;

		if (B < C || D < A) {
			answer = 0;
		} else {
			answer = Math.min(B, D) - Math.max(A, C);
		}

		System.out.println(answer);
	}
} public class Main {

	private static final String SHARP = "#";
	private static final String DOT = ".";

	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();
		int answer = 0;

		if (B < C || D < A) {
			answer = 0;
		} else {
			answer = Math.min(B, D) - Math.max(A, C);
		}

		System.out.println(answer);
	}
} Main
import java.util.Scanner;

public class Main {

	private static final String SHARP = "#";
	private static final String DOT = ".";

	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();
		int answer = 0;

		if (B < C || D < A) {
			answer = 0;
		} else {
			answer = Math.min(B, D) - Math.max(A, C);
		}

		System.out.println(answer);
	}
}
