import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int aliceStart = sc.nextInt();
		int aliceEnd = sc.nextInt();
		int bobStart = sc.nextInt();
		int bobEnd = sc.nextInt();
		int time = 0;

		if (aliceStart >= bobStart) {
			if (aliceEnd >= bobEnd) {
				time = bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0;
			} else {
				time = aliceEnd - aliceStart;
			}
		} else {
			if (bobEnd >= aliceEnd) {
				time = aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0;
			} else {
				time = bobEnd - bobStart;
			}
		}

		System.out.println(time);

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int aliceStart = sc.nextInt();
		int aliceEnd = sc.nextInt();
		int bobStart = sc.nextInt();
		int bobEnd = sc.nextInt();
		int time = 0;

		if (aliceStart >= bobStart) {
			if (aliceEnd >= bobEnd) {
				time = bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0;
			} else {
				time = aliceEnd - aliceStart;
			}
		} else {
			if (bobEnd >= aliceEnd) {
				time = aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0;
			} else {
				time = bobEnd - bobStart;
			}
		}

		System.out.println(time);

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int aliceStart = sc.nextInt();
		int aliceEnd = sc.nextInt();
		int bobStart = sc.nextInt();
		int bobEnd = sc.nextInt();
		int time = 0;

		if (aliceStart >= bobStart) {
			if (aliceEnd >= bobEnd) {
				time = bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0;
			} else {
				time = aliceEnd - aliceStart;
			}
		} else {
			if (bobEnd >= aliceEnd) {
				time = aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0;
			} else {
				time = bobEnd - bobStart;
			}
		}

		System.out.println(time);

	} main {
		Scanner sc = new Scanner(System.in);
		int aliceStart = sc.nextInt();
		int aliceEnd = sc.nextInt();
		int bobStart = sc.nextInt();
		int bobEnd = sc.nextInt();
		int time = 0;

		if (aliceStart >= bobStart) {
			if (aliceEnd >= bobEnd) {
				time = bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0;
			} else {
				time = aliceEnd - aliceStart;
			}
		} else {
			if (bobEnd >= aliceEnd) {
				time = aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0;
			} else {
				time = bobEnd - bobStart;
			}
		}

		System.out.println(time);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int aliceStart = sc.nextInt(); aliceStart sc.nextInt() sc.nextInt sc int aliceEnd = sc.nextInt(); aliceEnd sc.nextInt() sc.nextInt sc int bobStart = sc.nextInt(); bobStart sc.nextInt() sc.nextInt sc int bobEnd = sc.nextInt(); bobEnd sc.nextInt() sc.nextInt sc int time = 0; time 0 if (aliceStart >= bobStart) {
			if (aliceEnd >= bobEnd) {
				time = bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0;
			} else {
				time = aliceEnd - aliceStart;
			}
		} else {
			if (bobEnd >= aliceEnd) {
				time = aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0;
			} else {
				time = bobEnd - bobStart;
			}
		} aliceStart >= bobStart aliceStart bobStart {
			if (aliceEnd >= bobEnd) {
				time = bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0;
			} else {
				time = aliceEnd - aliceStart;
			}
		} if (aliceEnd >= bobEnd) {
				time = bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0;
			} else {
				time = aliceEnd - aliceStart;
			} aliceEnd >= bobEnd aliceEnd bobEnd {
				time = bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0;
			} time = bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0 time bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0 bobEnd - aliceStart > 0 bobEnd - aliceStart bobEnd aliceStart 0 bobEnd - aliceStart bobEnd aliceStart 0 {
				time = aliceEnd - aliceStart;
			} time = aliceEnd - aliceStart time aliceEnd - aliceStart aliceEnd aliceStart {
			if (bobEnd >= aliceEnd) {
				time = aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0;
			} else {
				time = bobEnd - bobStart;
			}
		} if (bobEnd >= aliceEnd) {
				time = aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0;
			} else {
				time = bobEnd - bobStart;
			} bobEnd >= aliceEnd bobEnd aliceEnd {
				time = aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0;
			} time = aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0 time aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0 aliceEnd - bobStart > 0 aliceEnd - bobStart aliceEnd bobStart 0 aliceEnd - bobStart aliceEnd bobStart 0 {
				time = bobEnd - bobStart;
			} time = bobEnd - bobStart time bobEnd - bobStart bobEnd bobStart System.out.println(time) System.out.println System.out System System.out time String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int aliceStart = sc.nextInt();
		int aliceEnd = sc.nextInt();
		int bobStart = sc.nextInt();
		int bobEnd = sc.nextInt();
		int time = 0;

		if (aliceStart >= bobStart) {
			if (aliceEnd >= bobEnd) {
				time = bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0;
			} else {
				time = aliceEnd - aliceStart;
			}
		} else {
			if (bobEnd >= aliceEnd) {
				time = aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0;
			} else {
				time = bobEnd - bobStart;
			}
		}

		System.out.println(time);

	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int aliceStart = sc.nextInt();
		int aliceEnd = sc.nextInt();
		int bobStart = sc.nextInt();
		int bobEnd = sc.nextInt();
		int time = 0;

		if (aliceStart >= bobStart) {
			if (aliceEnd >= bobEnd) {
				time = bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0;
			} else {
				time = aliceEnd - aliceStart;
			}
		} else {
			if (bobEnd >= aliceEnd) {
				time = aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0;
			} else {
				time = bobEnd - bobStart;
			}
		}

		System.out.println(time);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int aliceStart = sc.nextInt();
		int aliceEnd = sc.nextInt();
		int bobStart = sc.nextInt();
		int bobEnd = sc.nextInt();
		int time = 0;

		if (aliceStart >= bobStart) {
			if (aliceEnd >= bobEnd) {
				time = bobEnd - aliceStart > 0 ? bobEnd - aliceStart : 0;
			} else {
				time = aliceEnd - aliceStart;
			}
		} else {
			if (bobEnd >= aliceEnd) {
				time = aliceEnd - bobStart > 0 ? aliceEnd - bobStart : 0;
			} else {
				time = bobEnd - bobStart;
			}
		}

		System.out.println(time);

	}

}
