
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int ans = 0;
		if(B <= C || D <= A) {
			ans = 0;
		} else if(C <= A && A <= D && D <= B){
			ans = D - A;
		} else if(C <= A && B <= D) {
			ans = B - A;
		} else if(A <= C && C <= B && D <= B) {
			ans = D - C;
		} else if(A <= C && C <= B && B <= D) {
			ans = B - C;
		}
		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 = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int ans = 0;
		if(B <= C || D <= A) {
			ans = 0;
		} else if(C <= A && A <= D && D <= B){
			ans = D - A;
		} else if(C <= A && B <= D) {
			ans = B - A;
		} else if(A <= C && C <= B && D <= B) {
			ans = D - C;
		} else if(A <= C && C <= B && B <= D) {
			ans = B - C;
		}
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int ans = 0;
		if(B <= C || D <= A) {
			ans = 0;
		} else if(C <= A && A <= D && D <= B){
			ans = D - A;
		} else if(C <= A && B <= D) {
			ans = B - A;
		} else if(A <= C && C <= B && D <= B) {
			ans = D - C;
		} else if(A <= C && C <= B && B <= D) {
			ans = B - C;
		}
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int ans = 0;
		if(B <= C || D <= A) {
			ans = 0;
		} else if(C <= A && A <= D && D <= B){
			ans = D - A;
		} else if(C <= A && B <= D) {
			ans = B - A;
		} else if(A <= C && C <= B && D <= B) {
			ans = D - C;
		} else if(A <= C && C <= B && B <= D) {
			ans = B - C;
		}
		System.out.println(ans);
	} 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 ans = 0; ans 0 if(B <= C || D <= A) {
			ans = 0;
		} else if(C <= A && A <= D && D <= B){
			ans = D - A;
		} else if(C <= A && B <= D) {
			ans = B - A;
		} else if(A <= C && C <= B && D <= B) {
			ans = D - C;
		} else if(A <= C && C <= B && B <= D) {
			ans = B - C;
		} B <= C || D <= A B <= C B C D <= A D A {
			ans = 0;
		} ans = 0 ans 0 if(C <= A && A <= D && D <= B){
			ans = D - A;
		} else if(C <= A && B <= D) {
			ans = B - A;
		} else if(A <= C && C <= B && D <= B) {
			ans = D - C;
		} else if(A <= C && C <= B && B <= D) {
			ans = B - C;
		} C <= A && A <= D && D <= B C <= A && A <= D && D <= B C <= A C A A <= D A D D <= B D B {
			ans = D - A;
		} ans = D - A ans D - A D A if(C <= A && B <= D) {
			ans = B - A;
		} else if(A <= C && C <= B && D <= B) {
			ans = D - C;
		} else if(A <= C && C <= B && B <= D) {
			ans = B - C;
		} C <= A && B <= D C <= A C A B <= D B D {
			ans = B - A;
		} ans = B - A ans B - A B A if(A <= C && C <= B && D <= B) {
			ans = D - C;
		} else if(A <= C && C <= B && B <= D) {
			ans = B - C;
		} A <= C && C <= B && D <= B A <= C && C <= B && D <= B A <= C A C C <= B C B D <= B D B {
			ans = D - C;
		} ans = D - C ans D - C D C if(A <= C && C <= B && B <= D) {
			ans = B - C;
		} A <= C && C <= B && B <= D A <= C && C <= B && B <= D A <= C A C C <= B C B B <= D B D {
			ans = B - C;
		} ans = B - C ans B - C B C 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 = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int ans = 0;
		if(B <= C || D <= A) {
			ans = 0;
		} else if(C <= A && A <= D && D <= B){
			ans = D - A;
		} else if(C <= A && B <= D) {
			ans = B - A;
		} else if(A <= C && C <= B && D <= B) {
			ans = D - C;
		} else if(A <= C && C <= B && B <= D) {
			ans = B - C;
		}
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int ans = 0;
		if(B <= C || D <= A) {
			ans = 0;
		} else if(C <= A && A <= D && D <= B){
			ans = D - A;
		} else if(C <= A && B <= D) {
			ans = B - A;
		} else if(A <= C && C <= B && D <= B) {
			ans = D - C;
		} else if(A <= C && C <= B && B <= D) {
			ans = B - C;
		}
		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 = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int ans = 0;
		if(B <= C || D <= A) {
			ans = 0;
		} else if(C <= A && A <= D && D <= B){
			ans = D - A;
		} else if(C <= A && B <= D) {
			ans = B - A;
		} else if(A <= C && C <= B && D <= B) {
			ans = D - C;
		} else if(A <= C && C <= B && B <= D) {
			ans = B - C;
		}
		System.out.println(ans);
	}
}