import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();
		System.out.println((int)Math.min(B, D) - (int)Math.max(A, C) >= 0 ? (int)Math.min(B, D) - (int)Math.max(A, C) : 0);
		scan.close();

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();
		System.out.println((int)Math.min(B, D) - (int)Math.max(A, C) >= 0 ? (int)Math.min(B, D) - (int)Math.max(A, C) : 0);
		scan.close();

	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();
		System.out.println((int)Math.min(B, D) - (int)Math.max(A, C) >= 0 ? (int)Math.min(B, D) - (int)Math.max(A, C) : 0);
		scan.close();

	} main {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();
		System.out.println((int)Math.min(B, D) - (int)Math.max(A, C) >= 0 ? (int)Math.min(B, D) - (int)Math.max(A, C) : 0);
		scan.close();

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int A = scan.nextInt(); A scan.nextInt() scan.nextInt scan int B = scan.nextInt(); B scan.nextInt() scan.nextInt scan int C = scan.nextInt(); C scan.nextInt() scan.nextInt scan int D = scan.nextInt(); D scan.nextInt() scan.nextInt scan System.out.println((int)Math.min(B, D) - (int)Math.max(A, C) >= 0 ? (int)Math.min(B, D) - (int)Math.max(A, C) : 0) System.out.println System.out System System.out (int)Math.min(B, D) - (int)Math.max(A, C) >= 0 ? (int)Math.min(B, D) - (int)Math.max(A, C) : 0 (int)Math.min(B, D) - (int)Math.max(A, C) >= 0 (int)Math.min(B, D) - (int)Math.max(A, C) (int)Math.min(B, D) Math.min Math B D (int)Math.max(A, C) Math.max Math A C 0 (int)Math.min(B, D) - (int)Math.max(A, C) (int)Math.min(B, D) Math.min Math B D (int)Math.max(A, C) Math.max Math A C 0 scan.close() scan.close scan String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();
		System.out.println((int)Math.min(B, D) - (int)Math.max(A, C) >= 0 ? (int)Math.min(B, D) - (int)Math.max(A, C) : 0);
		scan.close();

	}

} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();
		System.out.println((int)Math.min(B, D) - (int)Math.max(A, C) >= 0 ? (int)Math.min(B, D) - (int)Math.max(A, C) : 0);
		scan.close();

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();
		System.out.println((int)Math.min(B, D) - (int)Math.max(A, C) >= 0 ? (int)Math.min(B, D) - (int)Math.max(A, C) : 0);
		scan.close();

	}

}
