import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer a = sc.nextInt();
		Integer b = sc.nextInt();
		Integer c = sc.nextInt();
		Integer d = sc.nextInt();

		int pp = Math.min(b, d) - Math.max(a, c);
		if (pp < 0)
			pp = 0;
		System.out.println(pp);
	}
} import java.io.*; io.* java import java.util.*; util.* java import java.lang.*; lang.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer a = sc.nextInt();
		Integer b = sc.nextInt();
		Integer c = sc.nextInt();
		Integer d = sc.nextInt();

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

		int pp = Math.min(b, d) - Math.max(a, c);
		if (pp < 0)
			pp = 0;
		System.out.println(pp);
	} main {
		Scanner sc = new Scanner(System.in);
		Integer a = sc.nextInt();
		Integer b = sc.nextInt();
		Integer c = sc.nextInt();
		Integer d = sc.nextInt();

		int pp = Math.min(b, d) - Math.max(a, c);
		if (pp < 0)
			pp = 0;
		System.out.println(pp);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Integer a = sc.nextInt(); a sc.nextInt() sc.nextInt sc Integer b = sc.nextInt(); b sc.nextInt() sc.nextInt sc Integer c = sc.nextInt(); c sc.nextInt() sc.nextInt sc Integer d = sc.nextInt(); d sc.nextInt() sc.nextInt sc int pp = Math.min(b, d) - Math.max(a, c); pp Math.min(b, d) - Math.max(a, c) Math.min(b, d) Math.min Math b d Math.max(a, c) Math.max Math a c if (pp < 0)
			pp = 0; pp < 0 pp 0 pp = 0 pp 0 System.out.println(pp) System.out.println System.out System System.out pp String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer a = sc.nextInt();
		Integer b = sc.nextInt();
		Integer c = sc.nextInt();
		Integer d = sc.nextInt();

		int pp = Math.min(b, d) - Math.max(a, c);
		if (pp < 0)
			pp = 0;
		System.out.println(pp);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer a = sc.nextInt();
		Integer b = sc.nextInt();
		Integer c = sc.nextInt();
		Integer d = sc.nextInt();

		int pp = Math.min(b, d) - Math.max(a, c);
		if (pp < 0)
			pp = 0;
		System.out.println(pp);
	}
} Main
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer a = sc.nextInt();
		Integer b = sc.nextInt();
		Integer c = sc.nextInt();
		Integer d = sc.nextInt();

		int pp = Math.min(b, d) - Math.max(a, c);
		if (pp < 0)
			pp = 0;
		System.out.println(pp);
	}
}
