import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(),B = sc.nextInt(),C = sc.nextInt(),D = sc.nextInt();
		int t1,t2;
		if(D<=A || B<=C)System.out.print(0);
		else {
			t1=(int)Math.max(C,A);
			t2=(int)Math.min(D,B);
			System.out.print(t2-t1);
		}
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(),B = sc.nextInt(),C = sc.nextInt(),D = sc.nextInt();
		int t1,t2;
		if(D<=A || B<=C)System.out.print(0);
		else {
			t1=(int)Math.max(C,A);
			t2=(int)Math.min(D,B);
			System.out.print(t2-t1);
		}
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(),B = sc.nextInt(),C = sc.nextInt(),D = sc.nextInt();
		int t1,t2;
		if(D<=A || B<=C)System.out.print(0);
		else {
			t1=(int)Math.max(C,A);
			t2=(int)Math.min(D,B);
			System.out.print(t2-t1);
		}
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(),B = sc.nextInt(),C = sc.nextInt(),D = sc.nextInt();
		int t1,t2;
		if(D<=A || B<=C)System.out.print(0);
		else {
			t1=(int)Math.max(C,A);
			t2=(int)Math.min(D,B);
			System.out.print(t2-t1);
		}
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int A = sc.nextInt() A sc.nextInt() sc.nextInt sc B = sc.nextInt() B sc.nextInt() sc.nextInt sc C = sc.nextInt() C sc.nextInt() sc.nextInt sc D = sc.nextInt(); D sc.nextInt() sc.nextInt sc int t1 t1 t2; t2 if(D<=A || B<=C)System.out.print(0);
		else {
			t1=(int)Math.max(C,A);
			t2=(int)Math.min(D,B);
			System.out.print(t2-t1);
		} D<=A || B<=C D<=A D A B<=C B C System.out.print(0) System.out.print System.out System System.out 0 {
			t1=(int)Math.max(C,A);
			t2=(int)Math.min(D,B);
			System.out.print(t2-t1);
		} t1=(int)Math.max(C,A) t1 (int)Math.max(C,A) Math.max Math C A t2=(int)Math.min(D,B) t2 (int)Math.min(D,B) Math.min Math D B System.out.print(t2-t1) System.out.print System.out System System.out t2-t1 t2 t1 sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(),B = sc.nextInt(),C = sc.nextInt(),D = sc.nextInt();
		int t1,t2;
		if(D<=A || B<=C)System.out.print(0);
		else {
			t1=(int)Math.max(C,A);
			t2=(int)Math.min(D,B);
			System.out.print(t2-t1);
		}
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(),B = sc.nextInt(),C = sc.nextInt(),D = sc.nextInt();
		int t1,t2;
		if(D<=A || B<=C)System.out.print(0);
		else {
			t1=(int)Math.max(C,A);
			t2=(int)Math.min(D,B);
			System.out.print(t2-t1);
		}
		sc.close();
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(),B = sc.nextInt(),C = sc.nextInt(),D = sc.nextInt();
		int t1,t2;
		if(D<=A || B<=C)System.out.print(0);
		else {
			t1=(int)Math.max(C,A);
			t2=(int)Math.min(D,B);
			System.out.print(t2-t1);
		}
		sc.close();
	}
}