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 (a >= c) {
			if (b <= d) {
				System.out.println(b - a);
			} else {
				System.out.println(d - a);
			}
		} else {
			if (b <= d) {
				System.out.println(b - c);
			} else {
				System.out.println(d - c);
			}
		}

		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();


		if (b <= c || d <= a) {
			System.out.println(0);
		} else if (a >= c) {
			if (b <= d) {
				System.out.println(b - a);
			} else {
				System.out.println(d - a);
			}
		} else {
			if (b <= d) {
				System.out.println(b - c);
			} else {
				System.out.println(d - c);
			}
		}

		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();


		if (b <= c || d <= a) {
			System.out.println(0);
		} else if (a >= c) {
			if (b <= d) {
				System.out.println(b - a);
			} else {
				System.out.println(d - a);
			}
		} else {
			if (b <= d) {
				System.out.println(b - c);
			} else {
				System.out.println(d - c);
			}
		}

		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();


		if (b <= c || d <= a) {
			System.out.println(0);
		} else if (a >= c) {
			if (b <= d) {
				System.out.println(b - a);
			} else {
				System.out.println(d - a);
			}
		} else {
			if (b <= d) {
				System.out.println(b - c);
			} else {
				System.out.println(d - c);
			}
		}

		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 if (b <= c || d <= a) {
			System.out.println(0);
		} else if (a >= c) {
			if (b <= d) {
				System.out.println(b - a);
			} else {
				System.out.println(d - a);
			}
		} else {
			if (b <= d) {
				System.out.println(b - c);
			} else {
				System.out.println(d - c);
			}
		} 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 (a >= c) {
			if (b <= d) {
				System.out.println(b - a);
			} else {
				System.out.println(d - a);
			}
		} else {
			if (b <= d) {
				System.out.println(b - c);
			} else {
				System.out.println(d - c);
			}
		} a >= c a c {
			if (b <= d) {
				System.out.println(b - a);
			} else {
				System.out.println(d - a);
			}
		} if (b <= d) {
				System.out.println(b - a);
			} else {
				System.out.println(d - a);
			} b <= d b d {
				System.out.println(b - a);
			} System.out.println(b - a) System.out.println System.out System System.out b - a b a {
				System.out.println(d - a);
			} System.out.println(d - a) System.out.println System.out System System.out d - a d a {
			if (b <= d) {
				System.out.println(b - c);
			} else {
				System.out.println(d - c);
			}
		} if (b <= d) {
				System.out.println(b - c);
			} else {
				System.out.println(d - c);
			} b <= d b d {
				System.out.println(b - c);
			} System.out.println(b - c) System.out.println System.out System System.out b - c b c {
				System.out.println(d - c);
			} System.out.println(d - c) System.out.println System.out System System.out d - c d c 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();


		if (b <= c || d <= a) {
			System.out.println(0);
		} else if (a >= c) {
			if (b <= d) {
				System.out.println(b - a);
			} else {
				System.out.println(d - a);
			}
		} else {
			if (b <= d) {
				System.out.println(b - c);
			} else {
				System.out.println(d - c);
			}
		}

		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();


		if (b <= c || d <= a) {
			System.out.println(0);
		} else if (a >= c) {
			if (b <= d) {
				System.out.println(b - a);
			} else {
				System.out.println(d - a);
			}
		} else {
			if (b <= d) {
				System.out.println(b - c);
			} else {
				System.out.println(d - c);
			}
		}

		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();


		if (b <= c || d <= a) {
			System.out.println(0);
		} else if (a >= c) {
			if (b <= d) {
				System.out.println(b - a);
			} else {
				System.out.println(d - a);
			}
		} else {
			if (b <= d) {
				System.out.println(b - c);
			} else {
				System.out.println(d - c);
			}
		}

		sc.close();
	}
}