import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		int start = Math.max(A, C);
		int end = Math.min(B, D);

		if (start > end){
			System.out.println("0");
		} else {
			System.out.println(end - start);
		}

	}

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

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		int start = Math.max(A, C);
		int end = Math.min(B, D);

		if (start > end){
			System.out.println("0");
		} else {
			System.out.println(end - start);
		}

	}

} Main public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		int start = Math.max(A, C);
		int end = Math.min(B, D);

		if (start > end){
			System.out.println("0");
		} else {
			System.out.println(end - start);
		}

	} main {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		int start = Math.max(A, C);
		int end = Math.min(B, D);

		if (start > end){
			System.out.println("0");
		} else {
			System.out.println(end - start);
		}

	} Scanner sc = new Scanner(System.in); sc 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 int start = Math.max(A, C); start Math.max(A, C) Math.max Math A C int end = Math.min(B, D); end Math.min(B, D) Math.min Math B D if (start > end){
			System.out.println("0");
		} else {
			System.out.println(end - start);
		} start > end start end {
			System.out.println("0");
		} System.out.println("0") System.out.println System.out System System.out "0" {
			System.out.println(end - start);
		} System.out.println(end - start) System.out.println System.out System System.out end - start end start String[] args args public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		int start = Math.max(A, C);
		int end = Math.min(B, D);

		if (start > end){
			System.out.println("0");
		} else {
			System.out.println(end - start);
		}

	}

} public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		int start = Math.max(A, C);
		int end = Math.min(B, D);

		if (start > end){
			System.out.println("0");
		} else {
			System.out.println(end - start);
		}

	}

} Main
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		int start = Math.max(A, C);
		int end = Math.min(B, D);

		if (start > end){
			System.out.println("0");
		} else {
			System.out.println(end - start);
		}

	}

}
