import java.util.Scanner;

public class Main {
	static long N;
	static long ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int L=sc.nextInt();
		int M=sc.nextInt();
		int start=Math.max(N, L);
		int end=Math.min(K, M);
		System.out.println(end-start<0?0:end-start);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static long N;
	static long ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int L=sc.nextInt();
		int M=sc.nextInt();
		int start=Math.max(N, L);
		int end=Math.min(K, M);
		System.out.println(end-start<0?0:end-start);
	}
} Main static long N; N static long ans; ans public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int L=sc.nextInt();
		int M=sc.nextInt();
		int start=Math.max(N, L);
		int end=Math.min(K, M);
		System.out.println(end-start<0?0:end-start);
	} main {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int L=sc.nextInt();
		int M=sc.nextInt();
		int start=Math.max(N, L);
		int end=Math.min(K, M);
		System.out.println(end-start<0?0:end-start);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N=sc.nextInt(); N sc.nextInt() sc.nextInt sc int K=sc.nextInt(); K sc.nextInt() sc.nextInt sc int L=sc.nextInt(); L sc.nextInt() sc.nextInt sc int M=sc.nextInt(); M sc.nextInt() sc.nextInt sc int start=Math.max(N, L); start Math.max(N, L) Math.max Math N L int end=Math.min(K, M); end Math.min(K, M) Math.min Math K M System.out.println(end-start<0?0:end-start) System.out.println System.out System System.out end-start<0?0:end-start end-start<0 end-start end start 0 0 end-start end start String[] args args public class Main {
	static long N;
	static long ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int L=sc.nextInt();
		int M=sc.nextInt();
		int start=Math.max(N, L);
		int end=Math.min(K, M);
		System.out.println(end-start<0?0:end-start);
	}
} public class Main {
	static long N;
	static long ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int L=sc.nextInt();
		int M=sc.nextInt();
		int start=Math.max(N, L);
		int end=Math.min(K, M);
		System.out.println(end-start<0?0:end-start);
	}
} Main
import java.util.Scanner;

public class Main {
	static long N;
	static long ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int L=sc.nextInt();
		int M=sc.nextInt();
		int start=Math.max(N, L);
		int end=Math.min(K, M);
		System.out.println(end-start<0?0:end-start);
	}
}
