import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static int AB = 26;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		int c = parseInt(sc.next());
		int d = parseInt(sc.next());
		sc.close();
		int dif = Math.min(b, d)-Math.max(a, c);
		dif = dif < 0?0:dif;
		out.println(dif);
	}
} import java.util.*; util.* java import java.io.PrintWriter; PrintWriter java.io import static java.lang.Integer.*; import static java.lang.Integer.*; import static java.lang.Integer.*; import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; public class Main {
	public static int AB = 26;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		int c = parseInt(sc.next());
		int d = parseInt(sc.next());
		sc.close();
		int dif = Math.min(b, d)-Math.max(a, c);
		dif = dif < 0?0:dif;
		out.println(dif);
	}
} Main public static int AB = 26; AB 26 public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		int c = parseInt(sc.next());
		int d = parseInt(sc.next());
		sc.close();
		int dif = Math.min(b, d)-Math.max(a, c);
		dif = dif < 0?0:dif;
		out.println(dif);
	} main {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		int c = parseInt(sc.next());
		int d = parseInt(sc.next());
		sc.close();
		int dif = Math.min(b, d)-Math.max(a, c);
		dif = dif < 0?0:dif;
		out.println(dif);
	} int i i j; j Scanner sc = new Scanner(in); sc new Scanner(in) int a = parseInt(sc.next()); a parseInt(sc.next()) parseInt sc.next() sc.next sc int b = parseInt(sc.next()); b parseInt(sc.next()) parseInt sc.next() sc.next sc int c = parseInt(sc.next()); c parseInt(sc.next()) parseInt sc.next() sc.next sc int d = parseInt(sc.next()); d parseInt(sc.next()) parseInt sc.next() sc.next sc sc.close() sc.close sc int dif = Math.min(b, d)-Math.max(a, c); dif 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 dif = dif < 0?0:dif dif dif < 0?0:dif dif < 0 dif 0 0 dif out.println(dif) out.println out dif String[] args args public class Main {
	public static int AB = 26;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		int c = parseInt(sc.next());
		int d = parseInt(sc.next());
		sc.close();
		int dif = Math.min(b, d)-Math.max(a, c);
		dif = dif < 0?0:dif;
		out.println(dif);
	}
} public class Main {
	public static int AB = 26;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		int c = parseInt(sc.next());
		int d = parseInt(sc.next());
		sc.close();
		int dif = Math.min(b, d)-Math.max(a, c);
		dif = dif < 0?0:dif;
		out.println(dif);
	}
} Main
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static int AB = 26;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		int c = parseInt(sc.next());
		int d = parseInt(sc.next());
		sc.close();
		int dif = Math.min(b, d)-Math.max(a, c);
		dif = dif < 0?0:dif;
		out.println(dif);
	}
}
