import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), D = sc.nextInt();
		int t = Math.min(B,D)-Math.max(A,C);
		System.out.println(t<0 ? 0 : t);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

} import java.util.*; util.* java public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), D = sc.nextInt();
		int t = Math.min(B,D)-Math.max(A,C);
		System.out.println(t<0 ? 0 : t);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

} Main static void solve() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), D = sc.nextInt();
		int t = Math.min(B,D)-Math.max(A,C);
		System.out.println(t<0 ? 0 : t);
		sc.close();		
	} solve {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), D = sc.nextInt();
		int t = Math.min(B,D)-Math.max(A,C);
		System.out.println(t<0 ? 0 : t);
		sc.close();		
	} 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 int t = Math.min(B,D)-Math.max(A,C); t 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 System.out.println(t<0 ? 0 : t) System.out.println System.out System System.out t<0 ? 0 : t t<0 t 0 0 t sc.close() sc.close sc public static void main(String args[]) {
		solve();
	} main {
		solve();
	} solve() solve String args[] args public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), D = sc.nextInt();
		int t = Math.min(B,D)-Math.max(A,C);
		System.out.println(t<0 ? 0 : t);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

} public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), D = sc.nextInt();
		int t = Math.min(B,D)-Math.max(A,C);
		System.out.println(t<0 ? 0 : t);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

} Main
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), D = sc.nextInt();
		int t = Math.min(B,D)-Math.max(A,C);
		System.out.println(t<0 ? 0 : t);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}