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