import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (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 || d <= a) {
				System.out.println(0);
				return;
			}
			if (a <= c && d <= b) {
				System.out.println(d - c);
				return;
			}
			if (c <= a && b <= d) {
				System.out.println(b - a);
				return;
			}
			System.out.println(Math.min(b, d) - Math.max(a, c));
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		try (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 || d <= a) {
				System.out.println(0);
				return;
			}
			if (a <= c && d <= b) {
				System.out.println(d - c);
				return;
			}
			if (c <= a && b <= d) {
				System.out.println(b - a);
				return;
			}
			System.out.println(Math.min(b, d) - Math.max(a, c));
		}
	}
} Main public static void main(String[] args) {
		try (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 || d <= a) {
				System.out.println(0);
				return;
			}
			if (a <= c && d <= b) {
				System.out.println(d - c);
				return;
			}
			if (c <= a && b <= d) {
				System.out.println(b - a);
				return;
			}
			System.out.println(Math.min(b, d) - Math.max(a, c));
		}
	} main {
		try (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 || d <= a) {
				System.out.println(0);
				return;
			}
			if (a <= c && d <= b) {
				System.out.println(d - c);
				return;
			}
			if (c <= a && b <= d) {
				System.out.println(b - a);
				return;
			}
			System.out.println(Math.min(b, d) - Math.max(a, c));
		}
	} try (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 || d <= a) {
				System.out.println(0);
				return;
			}
			if (a <= c && d <= b) {
				System.out.println(d - c);
				return;
			}
			if (c <= a && b <= d) {
				System.out.println(b - a);
				return;
			}
			System.out.println(Math.min(b, d) - Math.max(a, c));
		} {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int d = sc.nextInt();

			if (b <= c || d <= a) {
				System.out.println(0);
				return;
			}
			if (a <= c && d <= b) {
				System.out.println(d - c);
				return;
			}
			if (c <= a && b <= d) {
				System.out.println(b - a);
				return;
			}
			System.out.println(Math.min(b, d) - Math.max(a, c));
		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) 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 || d <= a) {
				System.out.println(0);
				return;
			} b <= c || d <= a b <= c b c d <= a d a {
				System.out.println(0);
				return;
			} System.out.println(0) System.out.println System.out System System.out 0 return; if (a <= c && d <= b) {
				System.out.println(d - c);
				return;
			} a <= c && d <= b a <= c a c d <= b d b {
				System.out.println(d - c);
				return;
			} System.out.println(d - c) System.out.println System.out System System.out d - c d c return; if (c <= a && b <= d) {
				System.out.println(b - a);
				return;
			} c <= a && b <= d c <= a c a b <= d b d {
				System.out.println(b - a);
				return;
			} System.out.println(b - a) System.out.println System.out System System.out b - a b a return; 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) {
		try (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 || d <= a) {
				System.out.println(0);
				return;
			}
			if (a <= c && d <= b) {
				System.out.println(d - c);
				return;
			}
			if (c <= a && b <= d) {
				System.out.println(b - a);
				return;
			}
			System.out.println(Math.min(b, d) - Math.max(a, c));
		}
	}
} public class Main {

	public static void main(String[] args) {
		try (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 || d <= a) {
				System.out.println(0);
				return;
			}
			if (a <= c && d <= b) {
				System.out.println(d - c);
				return;
			}
			if (c <= a && b <= d) {
				System.out.println(b - a);
				return;
			}
			System.out.println(Math.min(b, d) - Math.max(a, c));
		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (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 || d <= a) {
				System.out.println(0);
				return;
			}
			if (a <= c && d <= b) {
				System.out.println(d - c);
				return;
			}
			if (c <= a && b <= d) {
				System.out.println(b - a);
				return;
			}
			System.out.println(Math.min(b, d) - Math.max(a, c));
		}
	}
}
