import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int A = reader.nextInt();
		int B = reader.nextInt();
		int C = reader.nextInt();
		int D = reader.nextInt();
		int ans = Math.min(B, D) - Math.max(A, C);

		System.out.println(Math.max(ans, 0));
		reader.close();
	}


}


 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int A = reader.nextInt();
		int B = reader.nextInt();
		int C = reader.nextInt();
		int D = reader.nextInt();
		int ans = Math.min(B, D) - Math.max(A, C);

		System.out.println(Math.max(ans, 0));
		reader.close();
	}


} Main public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int A = reader.nextInt();
		int B = reader.nextInt();
		int C = reader.nextInt();
		int D = reader.nextInt();
		int ans = Math.min(B, D) - Math.max(A, C);

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

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

		System.out.println(Math.max(ans, 0));
		reader.close();
	}


} public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int A = reader.nextInt();
		int B = reader.nextInt();
		int C = reader.nextInt();
		int D = reader.nextInt();
		int ans = Math.min(B, D) - Math.max(A, C);

		System.out.println(Math.max(ans, 0));
		reader.close();
	}


} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int A = reader.nextInt();
		int B = reader.nextInt();
		int C = reader.nextInt();
		int D = reader.nextInt();
		int ans = Math.min(B, D) - Math.max(A, C);

		System.out.println(Math.max(ans, 0));
		reader.close();
	}


}



