import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();
		int ans = 0;

		if (c < a && d < a) {
			ans = 0;
		}
		if (c <= a && d >= a && d <= b) {
			ans = d - a;
		}

		if (c >= a && d <= b) {
			ans = d - c;
		}
		if (c >= a && d >= b && c <= b) {
			ans = b - c;
		}

		if (b < c) {
			ans = 0;
		}
		if (c <= a && b <= d) {
			ans = b - a;
		}

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

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();
		int ans = 0;

		if (c < a && d < a) {
			ans = 0;
		}
		if (c <= a && d >= a && d <= b) {
			ans = d - a;
		}

		if (c >= a && d <= b) {
			ans = d - c;
		}
		if (c >= a && d >= b && c <= b) {
			ans = b - c;
		}

		if (b < c) {
			ans = 0;
		}
		if (c <= a && b <= d) {
			ans = b - a;
		}

		System.out.println(ans);
	}
} Main @SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();
		int ans = 0;

		if (c < a && d < a) {
			ans = 0;
		}
		if (c <= a && d >= a && d <= b) {
			ans = d - a;
		}

		if (c >= a && d <= b) {
			ans = d - c;
		}
		if (c >= a && d >= b && c <= b) {
			ans = b - c;
		}

		if (b < c) {
			ans = 0;
		}
		if (c <= a && b <= d) {
			ans = b - a;
		}

		System.out.println(ans);
	} main {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();
		int ans = 0;

		if (c < a && d < a) {
			ans = 0;
		}
		if (c <= a && d >= a && d <= b) {
			ans = d - a;
		}

		if (c >= a && d <= b) {
			ans = d - c;
		}
		if (c >= a && d >= b && c <= b) {
			ans = b - c;
		}

		if (b < c) {
			ans = 0;
		}
		if (c <= a && b <= d) {
			ans = b - a;
		}

		System.out.println(ans);
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int a = scanner.nextInt(); a scanner.nextInt() scanner.nextInt scanner int b = scanner.nextInt(); b scanner.nextInt() scanner.nextInt scanner int c = scanner.nextInt(); c scanner.nextInt() scanner.nextInt scanner int d = scanner.nextInt(); d scanner.nextInt() scanner.nextInt scanner int ans = 0; ans 0 if (c < a && d < a) {
			ans = 0;
		} c < a && d < a c < a c a d < a d a {
			ans = 0;
		} ans = 0 ans 0 if (c <= a && d >= a && d <= b) {
			ans = d - a;
		} c <= a && d >= a && d <= b c <= a && d >= a && d <= b c <= a c a d >= a d a d <= b d b {
			ans = d - a;
		} ans = d - a ans d - a d a if (c >= a && d <= b) {
			ans = d - c;
		} c >= a && d <= b c >= a c a d <= b d b {
			ans = d - c;
		} ans = d - c ans d - c d c if (c >= a && d >= b && c <= b) {
			ans = b - c;
		} c >= a && d >= b && c <= b c >= a && d >= b && c <= b c >= a c a d >= b d b c <= b c b {
			ans = b - c;
		} ans = b - c ans b - c b c if (b < c) {
			ans = 0;
		} b < c b c {
			ans = 0;
		} ans = 0 ans 0 if (c <= a && b <= d) {
			ans = b - a;
		} c <= a && b <= d c <= a c a b <= d b d {
			ans = b - a;
		} ans = b - a ans b - a b a System.out.println(ans) System.out.println System.out System System.out ans String args[] args public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();
		int ans = 0;

		if (c < a && d < a) {
			ans = 0;
		}
		if (c <= a && d >= a && d <= b) {
			ans = d - a;
		}

		if (c >= a && d <= b) {
			ans = d - c;
		}
		if (c >= a && d >= b && c <= b) {
			ans = b - c;
		}

		if (b < c) {
			ans = 0;
		}
		if (c <= a && b <= d) {
			ans = b - a;
		}

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

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();
		int ans = 0;

		if (c < a && d < a) {
			ans = 0;
		}
		if (c <= a && d >= a && d <= b) {
			ans = d - a;
		}

		if (c >= a && d <= b) {
			ans = d - c;
		}
		if (c >= a && d >= b && c <= b) {
			ans = b - c;
		}

		if (b < c) {
			ans = 0;
		}
		if (c <= a && b <= d) {
			ans = b - a;
		}

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

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();
		int ans = 0;

		if (c < a && d < a) {
			ans = 0;
		}
		if (c <= a && d >= a && d <= b) {
			ans = d - a;
		}

		if (c >= a && d <= b) {
			ans = d - c;
		}
		if (c >= a && d >= b && c <= b) {
			ans = b - c;
		}

		if (b < c) {
			ans = 0;
		}
		if (c <= a && b <= d) {
			ans = b - a;
		}

		System.out.println(ans);
	}
}
