import 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 || A >= D){
			System.out.println(0);
		} else {
			System.out.println((B < D ? B : D)-(A > C ? A : C));
		}
	}
} import java.util.*; util.* java 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 || A >= D){
			System.out.println(0);
		} else {
			System.out.println((B < D ? B : D)-(A > C ? A : C));
		}
	}
} 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 || A >= D){
			System.out.println(0);
		} else {
			System.out.println((B < D ? B : D)-(A > C ? A : C));
		}
	} 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 || A >= D){
			System.out.println(0);
		} else {
			System.out.println((B < D ? B : D)-(A > C ? A : C));
		}
	} 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 || A >= D){
			System.out.println(0);
		} else {
			System.out.println((B < D ? B : D)-(A > C ? A : C));
		} B <= C || A >= D B <= C B C A >= D A D {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println((B < D ? B : D)-(A > C ? A : C));
		} System.out.println((B < D ? B : D)-(A > C ? A : C)) System.out.println System.out System System.out (B < D ? B : D)-(A > C ? A : C) (B < D ? B : D) B < D B D B D (A > C ? A : C) A > C A C A C 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 || A >= D){
			System.out.println(0);
		} else {
			System.out.println((B < D ? B : D)-(A > C ? A : C));
		}
	}
} 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 || A >= D){
			System.out.println(0);
		} else {
			System.out.println((B < D ? B : D)-(A > C ? A : C));
		}
	}
} Main
import 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 || A >= D){
			System.out.println(0);
		} else {
			System.out.println((B < D ? B : D)-(A > C ? A : C));
		}
	}
}