import java.util.Scanner;

class Main{
	public static void main(String arg[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();	
		sc.close();
		
		System.out.println(subAbs(A, B, C, D));
	}
	
	public static int subAbs(int A, int B, int C, int D){
		int sub = Math.min(B, D) - Math.max(A, C);
		if( sub > 0) {
			return sub;
		}else {
			return 0;
		}
	}
} import java.util.Scanner; Scanner java.util class Main{
	public static void main(String arg[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();	
		sc.close();
		
		System.out.println(subAbs(A, B, C, D));
	}
	
	public static int subAbs(int A, int B, int C, int D){
		int sub = Math.min(B, D) - Math.max(A, C);
		if( sub > 0) {
			return sub;
		}else {
			return 0;
		}
	}
} Main public static void main(String arg[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();	
		sc.close();
		
		System.out.println(subAbs(A, B, C, D));
	} main {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();	
		sc.close();
		
		System.out.println(subAbs(A, B, C, D));
	} 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 sc.close() sc.close sc System.out.println(subAbs(A, B, C, D)) System.out.println System.out System System.out subAbs(A, B, C, D) subAbs A B C D String arg[] arg public static int subAbs(int A, int B, int C, int D){
		int sub = Math.min(B, D) - Math.max(A, C);
		if( sub > 0) {
			return sub;
		}else {
			return 0;
		}
	} subAbs {
		int sub = Math.min(B, D) - Math.max(A, C);
		if( sub > 0) {
			return sub;
		}else {
			return 0;
		}
	} int sub = Math.min(B, D) - Math.max(A, C); sub 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 if( sub > 0) {
			return sub;
		}else {
			return 0;
		} sub > 0 sub 0 {
			return sub;
		} return sub; sub {
			return 0;
		} return 0; 0 int A A int B B int C C int D D
import java.util.Scanner;

class Main{
	public static void main(String arg[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();	
		sc.close();
		
		System.out.println(subAbs(A, B, C, D));
	}
	
	public static int subAbs(int A, int B, int C, int D){
		int sub = Math.min(B, D) - Math.max(A, C);
		if( sub > 0) {
			return sub;
		}else {
			return 0;
		}
	}
}