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