import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A, B, C, D;
		int start, end;
		int ans;

		A = Integer.parseInt(sc.next());
		B = Integer.parseInt(sc.next());
		C = Integer.parseInt(sc.next());
		D = Integer.parseInt(sc.next());

		if(B < C || D < A){
			ans = 0;
		}else{
			start = Math.max(A, C);
			end = Math.min(B, D);
			ans = end - start;
		}

		System.out.println(ans);

	}

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

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A, B, C, D;
		int start, end;
		int ans;

		A = Integer.parseInt(sc.next());
		B = Integer.parseInt(sc.next());
		C = Integer.parseInt(sc.next());
		D = Integer.parseInt(sc.next());

		if(B < C || D < A){
			ans = 0;
		}else{
			start = Math.max(A, C);
			end = Math.min(B, D);
			ans = end - start;
		}

		System.out.println(ans);

	}

} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A, B, C, D;
		int start, end;
		int ans;

		A = Integer.parseInt(sc.next());
		B = Integer.parseInt(sc.next());
		C = Integer.parseInt(sc.next());
		D = Integer.parseInt(sc.next());

		if(B < C || D < A){
			ans = 0;
		}else{
			start = Math.max(A, C);
			end = Math.min(B, D);
			ans = end - start;
		}

		System.out.println(ans);

	} main {

		Scanner sc = new Scanner(System.in);

		int A, B, C, D;
		int start, end;
		int ans;

		A = Integer.parseInt(sc.next());
		B = Integer.parseInt(sc.next());
		C = Integer.parseInt(sc.next());
		D = Integer.parseInt(sc.next());

		if(B < C || D < A){
			ans = 0;
		}else{
			start = Math.max(A, C);
			end = Math.min(B, D);
			ans = end - start;
		}

		System.out.println(ans);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int A A B B C C D; D int start start end; end int ans; ans A = Integer.parseInt(sc.next()) A Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc B = Integer.parseInt(sc.next()) B Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc C = Integer.parseInt(sc.next()) C Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc D = Integer.parseInt(sc.next()) D Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(B < C || D < A){
			ans = 0;
		}else{
			start = Math.max(A, C);
			end = Math.min(B, D);
			ans = end - start;
		} B < C || D < A B < C B C D < A D A {
			ans = 0;
		} ans = 0 ans 0 {
			start = Math.max(A, C);
			end = Math.min(B, D);
			ans = end - start;
		} start = Math.max(A, C) start Math.max(A, C) Math.max Math A C end = Math.min(B, D) end Math.min(B, D) Math.min Math B D ans = end - start ans end - start end start System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A, B, C, D;
		int start, end;
		int ans;

		A = Integer.parseInt(sc.next());
		B = Integer.parseInt(sc.next());
		C = Integer.parseInt(sc.next());
		D = Integer.parseInt(sc.next());

		if(B < C || D < A){
			ans = 0;
		}else{
			start = Math.max(A, C);
			end = Math.min(B, D);
			ans = end - start;
		}

		System.out.println(ans);

	}

} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A, B, C, D;
		int start, end;
		int ans;

		A = Integer.parseInt(sc.next());
		B = Integer.parseInt(sc.next());
		C = Integer.parseInt(sc.next());
		D = Integer.parseInt(sc.next());

		if(B < C || D < A){
			ans = 0;
		}else{
			start = Math.max(A, C);
			end = Math.min(B, D);
			ans = end - start;
		}

		System.out.println(ans);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A, B, C, D;
		int start, end;
		int ans;

		A = Integer.parseInt(sc.next());
		B = Integer.parseInt(sc.next());
		C = Integer.parseInt(sc.next());
		D = Integer.parseInt(sc.next());

		if(B < C || D < A){
			ans = 0;
		}else{
			start = Math.max(A, C);
			end = Math.min(B, D);
			ans = end - start;
		}

		System.out.println(ans);

	}

}