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();
		
		if(B <= C || D <= A) {
			System.out.println(0);
		} else if(C < B && B <= D && A <= C) {
			System.out.println(B - C);
		} else if(A <= C && D < B) {
			System.out.println(D - C);
		} else if(C < A && A <= D && D <= B) {
			System.out.println(D - A);
		} else {
			System.out.println(B - A);
		}
				
	}
} 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();
		
		if(B <= C || D <= A) {
			System.out.println(0);
		} else if(C < B && B <= D && A <= C) {
			System.out.println(B - C);
		} else if(A <= C && D < B) {
			System.out.println(D - C);
		} else if(C < A && A <= D && D <= B) {
			System.out.println(D - A);
		} else {
			System.out.println(B - A);
		}
				
	}
} 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();
		
		if(B <= C || D <= A) {
			System.out.println(0);
		} else if(C < B && B <= D && A <= C) {
			System.out.println(B - C);
		} else if(A <= C && D < B) {
			System.out.println(D - C);
		} else if(C < A && A <= D && D <= B) {
			System.out.println(D - A);
		} else {
			System.out.println(B - A);
		}
				
	} main {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		
		if(B <= C || D <= A) {
			System.out.println(0);
		} else if(C < B && B <= D && A <= C) {
			System.out.println(B - C);
		} else if(A <= C && D < B) {
			System.out.println(D - C);
		} else if(C < A && A <= D && D <= B) {
			System.out.println(D - A);
		} else {
			System.out.println(B - A);
		}
				
	} 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 if(B <= C || D <= A) {
			System.out.println(0);
		} else if(C < B && B <= D && A <= C) {
			System.out.println(B - C);
		} else if(A <= C && D < B) {
			System.out.println(D - C);
		} else if(C < A && A <= D && D <= B) {
			System.out.println(D - A);
		} else {
			System.out.println(B - A);
		} B <= C || D <= A B <= C B C D <= A D A {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 if(C < B && B <= D && A <= C) {
			System.out.println(B - C);
		} else if(A <= C && D < B) {
			System.out.println(D - C);
		} else if(C < A && A <= D && D <= B) {
			System.out.println(D - A);
		} else {
			System.out.println(B - A);
		} C < B && B <= D && A <= C C < B && B <= D && A <= C C < B C B B <= D B D A <= C A C {
			System.out.println(B - C);
		} System.out.println(B - C) System.out.println System.out System System.out B - C B C if(A <= C && D < B) {
			System.out.println(D - C);
		} else if(C < A && A <= D && D <= B) {
			System.out.println(D - A);
		} else {
			System.out.println(B - A);
		} A <= C && D < B A <= C A C D < B D B {
			System.out.println(D - C);
		} System.out.println(D - C) System.out.println System.out System System.out D - C D C if(C < A && A <= D && D <= B) {
			System.out.println(D - A);
		} else {
			System.out.println(B - A);
		} C < A && A <= D && D <= B C < A && A <= D && D <= B C < A C A A <= D A D D <= B D B {
			System.out.println(D - A);
		} System.out.println(D - A) System.out.println System.out System System.out D - A D A {
			System.out.println(B - A);
		} System.out.println(B - A) System.out.println System.out System System.out B - A B A 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();
		
		if(B <= C || D <= A) {
			System.out.println(0);
		} else if(C < B && B <= D && A <= C) {
			System.out.println(B - C);
		} else if(A <= C && D < B) {
			System.out.println(D - C);
		} else if(C < A && A <= D && D <= B) {
			System.out.println(D - A);
		} else {
			System.out.println(B - A);
		}
				
	}
} 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();
		
		if(B <= C || D <= A) {
			System.out.println(0);
		} else if(C < B && B <= D && A <= C) {
			System.out.println(B - C);
		} else if(A <= C && D < B) {
			System.out.println(D - C);
		} else if(C < A && A <= D && D <= B) {
			System.out.println(D - A);
		} else {
			System.out.println(B - A);
		}
				
	}
} 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();
		
		if(B <= C || D <= A) {
			System.out.println(0);
		} else if(C < B && B <= D && A <= C) {
			System.out.println(B - C);
		} else if(A <= C && D < B) {
			System.out.println(D - C);
		} else if(C < A && A <= D && D <= B) {
			System.out.println(D - A);
		} else {
			System.out.println(B - A);
		}
				
	}
}
