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();
		sc.close();
		
		if(A > D || B < C)
			System.out.println("0");
		else {
			int x = B > D ? D : B;
			if(A < C)
				System.out.println((x - C));
			else
				System.out.println((x - A));
		}
	}
} 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();
		sc.close();
		
		if(A > D || B < C)
			System.out.println("0");
		else {
			int x = B > D ? D : B;
			if(A < C)
				System.out.println((x - C));
			else
				System.out.println((x - A));
		}
	}
} 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();
		sc.close();
		
		if(A > D || B < C)
			System.out.println("0");
		else {
			int x = B > D ? D : B;
			if(A < C)
				System.out.println((x - C));
			else
				System.out.println((x - A));
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		sc.close();
		
		if(A > D || B < C)
			System.out.println("0");
		else {
			int x = B > D ? D : B;
			if(A < C)
				System.out.println((x - C));
			else
				System.out.println((x - A));
		}
	} 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 sc.close() sc.close sc if(A > D || B < C)
			System.out.println("0");
		else {
			int x = B > D ? D : B;
			if(A < C)
				System.out.println((x - C));
			else
				System.out.println((x - A));
		} A > D || B < C A > D A D B < C B C System.out.println("0") System.out.println System.out System System.out "0" {
			int x = B > D ? D : B;
			if(A < C)
				System.out.println((x - C));
			else
				System.out.println((x - A));
		} int x = B > D ? D : B; x B > D ? D : B B > D B D D B if(A < C)
				System.out.println((x - C));
			else
				System.out.println((x - A)); A < C A C System.out.println((x - C)) System.out.println System.out System System.out (x - C) x C System.out.println((x - A)) System.out.println System.out System System.out (x - A) x A 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();
		sc.close();
		
		if(A > D || B < C)
			System.out.println("0");
		else {
			int x = B > D ? D : B;
			if(A < C)
				System.out.println((x - C));
			else
				System.out.println((x - A));
		}
	}
} 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();
		sc.close();
		
		if(A > D || B < C)
			System.out.println("0");
		else {
			int x = B > D ? D : B;
			if(A < C)
				System.out.println((x - C));
			else
				System.out.println((x - A));
		}
	}
} 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();
		sc.close();
		
		if(A > D || B < C)
			System.out.println("0");
		else {
			int x = B > D ? D : B;
			if(A < C)
				System.out.println((x - C));
			else
				System.out.println((x - A));
		}
	}
}
