import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tempList = scanner.nextLine().split(" ");
		int A = Integer.parseInt(tempList[0]);
		int B = Integer.parseInt(tempList[1]);
		int C = Integer.parseInt(tempList[2]);
		int D = Integer.parseInt(tempList[3]);
		int result = 0;
			if(A >= C) {
				if(B >= D) {
					result = D - A;
				}else {
					result = B - A;
				}
			}else {
				if(B >= D) {
					result = D - C;
				}else {
					result = B - C;
				}
		}
		if(result < 0) {result = 0;}
		System.out.println(result);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tempList = scanner.nextLine().split(" ");
		int A = Integer.parseInt(tempList[0]);
		int B = Integer.parseInt(tempList[1]);
		int C = Integer.parseInt(tempList[2]);
		int D = Integer.parseInt(tempList[3]);
		int result = 0;
			if(A >= C) {
				if(B >= D) {
					result = D - A;
				}else {
					result = B - A;
				}
			}else {
				if(B >= D) {
					result = D - C;
				}else {
					result = B - C;
				}
		}
		if(result < 0) {result = 0;}
		System.out.println(result);
	}
} Main public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tempList = scanner.nextLine().split(" ");
		int A = Integer.parseInt(tempList[0]);
		int B = Integer.parseInt(tempList[1]);
		int C = Integer.parseInt(tempList[2]);
		int D = Integer.parseInt(tempList[3]);
		int result = 0;
			if(A >= C) {
				if(B >= D) {
					result = D - A;
				}else {
					result = B - A;
				}
			}else {
				if(B >= D) {
					result = D - C;
				}else {
					result = B - C;
				}
		}
		if(result < 0) {result = 0;}
		System.out.println(result);
	} main {

		Scanner scanner = new Scanner(System.in);

		String[] tempList = scanner.nextLine().split(" ");
		int A = Integer.parseInt(tempList[0]);
		int B = Integer.parseInt(tempList[1]);
		int C = Integer.parseInt(tempList[2]);
		int D = Integer.parseInt(tempList[3]);
		int result = 0;
			if(A >= C) {
				if(B >= D) {
					result = D - A;
				}else {
					result = B - A;
				}
			}else {
				if(B >= D) {
					result = D - C;
				}else {
					result = B - C;
				}
		}
		if(result < 0) {result = 0;}
		System.out.println(result);
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String[] tempList = scanner.nextLine().split(" "); tempList scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " int A = Integer.parseInt(tempList[0]); A Integer.parseInt(tempList[0]) Integer.parseInt Integer tempList[0] tempList 0 int B = Integer.parseInt(tempList[1]); B Integer.parseInt(tempList[1]) Integer.parseInt Integer tempList[1] tempList 1 int C = Integer.parseInt(tempList[2]); C Integer.parseInt(tempList[2]) Integer.parseInt Integer tempList[2] tempList 2 int D = Integer.parseInt(tempList[3]); D Integer.parseInt(tempList[3]) Integer.parseInt Integer tempList[3] tempList 3 int result = 0; result 0 if(A >= C) {
				if(B >= D) {
					result = D - A;
				}else {
					result = B - A;
				}
			}else {
				if(B >= D) {
					result = D - C;
				}else {
					result = B - C;
				}
		} A >= C A C {
				if(B >= D) {
					result = D - A;
				}else {
					result = B - A;
				}
			} if(B >= D) {
					result = D - A;
				}else {
					result = B - A;
				} B >= D B D {
					result = D - A;
				} result = D - A result D - A D A {
					result = B - A;
				} result = B - A result B - A B A {
				if(B >= D) {
					result = D - C;
				}else {
					result = B - C;
				}
		} if(B >= D) {
					result = D - C;
				}else {
					result = B - C;
				} B >= D B D {
					result = D - C;
				} result = D - C result D - C D C {
					result = B - C;
				} result = B - C result B - C B C if(result < 0) {result = 0;} result < 0 result 0 {result = 0;} result = 0 result 0 System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tempList = scanner.nextLine().split(" ");
		int A = Integer.parseInt(tempList[0]);
		int B = Integer.parseInt(tempList[1]);
		int C = Integer.parseInt(tempList[2]);
		int D = Integer.parseInt(tempList[3]);
		int result = 0;
			if(A >= C) {
				if(B >= D) {
					result = D - A;
				}else {
					result = B - A;
				}
			}else {
				if(B >= D) {
					result = D - C;
				}else {
					result = B - C;
				}
		}
		if(result < 0) {result = 0;}
		System.out.println(result);
	}
} public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tempList = scanner.nextLine().split(" ");
		int A = Integer.parseInt(tempList[0]);
		int B = Integer.parseInt(tempList[1]);
		int C = Integer.parseInt(tempList[2]);
		int D = Integer.parseInt(tempList[3]);
		int result = 0;
			if(A >= C) {
				if(B >= D) {
					result = D - A;
				}else {
					result = B - A;
				}
			}else {
				if(B >= D) {
					result = D - C;
				}else {
					result = B - C;
				}
		}
		if(result < 0) {result = 0;}
		System.out.println(result);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tempList = scanner.nextLine().split(" ");
		int A = Integer.parseInt(tempList[0]);
		int B = Integer.parseInt(tempList[1]);
		int C = Integer.parseInt(tempList[2]);
		int D = Integer.parseInt(tempList[3]);
		int result = 0;
			if(A >= C) {
				if(B >= D) {
					result = D - A;
				}else {
					result = B - A;
				}
			}else {
				if(B >= D) {
					result = D - C;
				}else {
					result = B - C;
				}
		}
		if(result < 0) {result = 0;}
		System.out.println(result);
	}
}