import static java.lang.Math.max;
import static java.lang.Math.min;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
			System.out.println(max(min(b, d) - max(a, c), 0));
		}
	}
} import static java.lang.Math.max; import static java.lang.Math.max; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.min; import static java.lang.Math.min; import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
			System.out.println(max(min(b, d) - max(a, c), 0));
		}
	}
} Main public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
			System.out.println(max(min(b, d) - max(a, c), 0));
		}
	} main {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
			System.out.println(max(min(b, d) - max(a, c), 0));
		}
	} try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
			System.out.println(max(min(b, d) - max(a, c), 0));
		} {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
			System.out.println(max(min(b, d) - max(a, c), 0));
		} Scanner scanner = new Scanner(System.in) Scanner scanner = new Scanner(System.in) new Scanner(System.in) int a = scanner.nextInt() a scanner.nextInt() scanner.nextInt scanner b = scanner.nextInt() b scanner.nextInt() scanner.nextInt scanner c = scanner.nextInt() c scanner.nextInt() scanner.nextInt scanner d = scanner.nextInt(); d scanner.nextInt() scanner.nextInt scanner System.out.println(max(min(b, d) - max(a, c), 0)) System.out.println System.out System System.out max(min(b, d) - max(a, c), 0) max min(b, d) - max(a, c) min(b, d) min b d max(a, c) max a c 0 String[] args args public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
			System.out.println(max(min(b, d) - max(a, c), 0));
		}
	}
} public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
			System.out.println(max(min(b, d) - max(a, c), 0));
		}
	}
} Main
import static java.lang.Math.max;
import static java.lang.Math.min;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
			System.out.println(max(min(b, d) - max(a, c), 0));
		}
	}
}
