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();
		int start = Math.max(a, c);
		int end = Math.min(b, d);
		int on = 0;
		if (end > start) {
			on = end - start;
		}
		System.out.println(on);
	}
} 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();
		int start = Math.max(a, c);
		int end = Math.min(b, d);
		int on = 0;
		if (end > start) {
			on = end - start;
		}
		System.out.println(on);
	}
} 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 start = Math.max(a, c);
		int end = Math.min(b, d);
		int on = 0;
		if (end > start) {
			on = end - start;
		}
		System.out.println(on);
	} main {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int start = Math.max(a, c);
		int end = Math.min(b, d);
		int on = 0;
		if (end > start) {
			on = end - start;
		}
		System.out.println(on);
	} 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 start = Math.max(a, c); start Math.max(a, c) Math.max Math a c int end = Math.min(b, d); end Math.min(b, d) Math.min Math b d int on = 0; on 0 if (end > start) {
			on = end - start;
		} end > start end start {
			on = end - start;
		} on = end - start on end - start end start System.out.println(on) System.out.println System.out System System.out on 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 start = Math.max(a, c);
		int end = Math.min(b, d);
		int on = 0;
		if (end > start) {
			on = end - start;
		}
		System.out.println(on);
	}
} 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 start = Math.max(a, c);
		int end = Math.min(b, d);
		int on = 0;
		if (end > start) {
			on = end - start;
		}
		System.out.println(on);
	}
} 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();
		int start = Math.max(a, c);
		int end = Math.min(b, d);
		int on = 0;
		if (end > start) {
			on = end - start;
		}
		System.out.println(on);
	}
}
