import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),d = sc.nextInt();
		if(b<c || a>d) {
			System.out.println(0);
		}else if(c<=a) {
			System.out.println(Math.min(b,d)-a);
		}else if(b<=d) {
			System.out.println(b-Math.max(a, c));
		}else if(c<=b) {
			System.out.println(Math.min(b,d)-c);
		}else if(a<=d) {
			System.out.println(d-Math.max(a, c));
		}
	}
	public static int sample() {
		return 1;
	}

} 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(),b = sc.nextInt(),c = sc.nextInt(),d = sc.nextInt();
		if(b<c || a>d) {
			System.out.println(0);
		}else if(c<=a) {
			System.out.println(Math.min(b,d)-a);
		}else if(b<=d) {
			System.out.println(b-Math.max(a, c));
		}else if(c<=b) {
			System.out.println(Math.min(b,d)-c);
		}else if(a<=d) {
			System.out.println(d-Math.max(a, c));
		}
	}
	public static int sample() {
		return 1;
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),d = sc.nextInt();
		if(b<c || a>d) {
			System.out.println(0);
		}else if(c<=a) {
			System.out.println(Math.min(b,d)-a);
		}else if(b<=d) {
			System.out.println(b-Math.max(a, c));
		}else if(c<=b) {
			System.out.println(Math.min(b,d)-c);
		}else if(a<=d) {
			System.out.println(d-Math.max(a, c));
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),d = sc.nextInt();
		if(b<c || a>d) {
			System.out.println(0);
		}else if(c<=a) {
			System.out.println(Math.min(b,d)-a);
		}else if(b<=d) {
			System.out.println(b-Math.max(a, c));
		}else if(c<=b) {
			System.out.println(Math.min(b,d)-c);
		}else if(a<=d) {
			System.out.println(d-Math.max(a, c));
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int 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(b<c || a>d) {
			System.out.println(0);
		}else if(c<=a) {
			System.out.println(Math.min(b,d)-a);
		}else if(b<=d) {
			System.out.println(b-Math.max(a, c));
		}else if(c<=b) {
			System.out.println(Math.min(b,d)-c);
		}else if(a<=d) {
			System.out.println(d-Math.max(a, c));
		} b<c || a>d b<c b c a>d a d {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 if(c<=a) {
			System.out.println(Math.min(b,d)-a);
		}else if(b<=d) {
			System.out.println(b-Math.max(a, c));
		}else if(c<=b) {
			System.out.println(Math.min(b,d)-c);
		}else if(a<=d) {
			System.out.println(d-Math.max(a, c));
		} c<=a c a {
			System.out.println(Math.min(b,d)-a);
		} System.out.println(Math.min(b,d)-a) System.out.println System.out System System.out Math.min(b,d)-a Math.min(b,d) Math.min Math b d a if(b<=d) {
			System.out.println(b-Math.max(a, c));
		}else if(c<=b) {
			System.out.println(Math.min(b,d)-c);
		}else if(a<=d) {
			System.out.println(d-Math.max(a, c));
		} b<=d b d {
			System.out.println(b-Math.max(a, c));
		} System.out.println(b-Math.max(a, c)) System.out.println System.out System System.out b-Math.max(a, c) b Math.max(a, c) Math.max Math a c if(c<=b) {
			System.out.println(Math.min(b,d)-c);
		}else if(a<=d) {
			System.out.println(d-Math.max(a, c));
		} c<=b c b {
			System.out.println(Math.min(b,d)-c);
		} System.out.println(Math.min(b,d)-c) System.out.println System.out System System.out Math.min(b,d)-c Math.min(b,d) Math.min Math b d c if(a<=d) {
			System.out.println(d-Math.max(a, c));
		} a<=d a d {
			System.out.println(d-Math.max(a, c));
		} System.out.println(d-Math.max(a, c)) System.out.println System.out System System.out d-Math.max(a, c) d Math.max(a, c) Math.max Math a c String[] args args public static int sample() {
		return 1;
	} sample {
		return 1;
	} return 1; 1 public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),d = sc.nextInt();
		if(b<c || a>d) {
			System.out.println(0);
		}else if(c<=a) {
			System.out.println(Math.min(b,d)-a);
		}else if(b<=d) {
			System.out.println(b-Math.max(a, c));
		}else if(c<=b) {
			System.out.println(Math.min(b,d)-c);
		}else if(a<=d) {
			System.out.println(d-Math.max(a, c));
		}
	}
	public static int sample() {
		return 1;
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),d = sc.nextInt();
		if(b<c || a>d) {
			System.out.println(0);
		}else if(c<=a) {
			System.out.println(Math.min(b,d)-a);
		}else if(b<=d) {
			System.out.println(b-Math.max(a, c));
		}else if(c<=b) {
			System.out.println(Math.min(b,d)-c);
		}else if(a<=d) {
			System.out.println(d-Math.max(a, c));
		}
	}
	public static int sample() {
		return 1;
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),d = sc.nextInt();
		if(b<c || a>d) {
			System.out.println(0);
		}else if(c<=a) {
			System.out.println(Math.min(b,d)-a);
		}else if(b<=d) {
			System.out.println(b-Math.max(a, c));
		}else if(c<=b) {
			System.out.println(Math.min(b,d)-c);
		}else if(a<=d) {
			System.out.println(d-Math.max(a, c));
		}
	}
	public static int sample() {
		return 1;
	}

}
