import java.util.*;
public class Main{
	static int TwoSwitches(int p, int q, int r, int s){
		if(q<=r)return 0;
		else if(p<=r && r<=q && q<=s)return q-r;
		else if(r<=p && q<=s)return q-p;
		else if(p<=r && s<=q)return s-r;
		else if(r<=p && p<=s && s<=q)return s-p;
		else return 0;
	}

	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();
		System.out.println(TwoSwitches(a, b, c, d));
	}
} import java.util.*; util.* java public class Main{
	static int TwoSwitches(int p, int q, int r, int s){
		if(q<=r)return 0;
		else if(p<=r && r<=q && q<=s)return q-r;
		else if(r<=p && q<=s)return q-p;
		else if(p<=r && s<=q)return s-r;
		else if(r<=p && p<=s && s<=q)return s-p;
		else return 0;
	}

	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();
		System.out.println(TwoSwitches(a, b, c, d));
	}
} Main static int TwoSwitches(int p, int q, int r, int s){
		if(q<=r)return 0;
		else if(p<=r && r<=q && q<=s)return q-r;
		else if(r<=p && q<=s)return q-p;
		else if(p<=r && s<=q)return s-r;
		else if(r<=p && p<=s && s<=q)return s-p;
		else return 0;
	} TwoSwitches {
		if(q<=r)return 0;
		else if(p<=r && r<=q && q<=s)return q-r;
		else if(r<=p && q<=s)return q-p;
		else if(p<=r && s<=q)return s-r;
		else if(r<=p && p<=s && s<=q)return s-p;
		else return 0;
	} if(q<=r)return 0;
		else if(p<=r && r<=q && q<=s)return q-r;
		else if(r<=p && q<=s)return q-p;
		else if(p<=r && s<=q)return s-r;
		else if(r<=p && p<=s && s<=q)return s-p;
		else return 0; q<=r q r return 0; 0 if(p<=r && r<=q && q<=s)return q-r;
		else if(r<=p && q<=s)return q-p;
		else if(p<=r && s<=q)return s-r;
		else if(r<=p && p<=s && s<=q)return s-p;
		else return 0; p<=r && r<=q && q<=s p<=r && r<=q && q<=s p<=r p r r<=q r q q<=s q s return q-r; q-r q r if(r<=p && q<=s)return q-p;
		else if(p<=r && s<=q)return s-r;
		else if(r<=p && p<=s && s<=q)return s-p;
		else return 0; r<=p && q<=s r<=p r p q<=s q s return q-p; q-p q p if(p<=r && s<=q)return s-r;
		else if(r<=p && p<=s && s<=q)return s-p;
		else return 0; p<=r && s<=q p<=r p r s<=q s q return s-r; s-r s r if(r<=p && p<=s && s<=q)return s-p;
		else return 0; r<=p && p<=s && s<=q r<=p && p<=s && s<=q r<=p r p p<=s p s s<=q s q return s-p; s-p s p return 0; 0 int p p int q q int r r int s s 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();
		System.out.println(TwoSwitches(a, b, c, d));
	} main {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		System.out.println(TwoSwitches(a, b, c, d));
	} 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 System.out.println(TwoSwitches(a, b, c, d)) System.out.println System.out System System.out TwoSwitches(a, b, c, d) TwoSwitches a b c d String[] args args public class Main{
	static int TwoSwitches(int p, int q, int r, int s){
		if(q<=r)return 0;
		else if(p<=r && r<=q && q<=s)return q-r;
		else if(r<=p && q<=s)return q-p;
		else if(p<=r && s<=q)return s-r;
		else if(r<=p && p<=s && s<=q)return s-p;
		else return 0;
	}

	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();
		System.out.println(TwoSwitches(a, b, c, d));
	}
} public class Main{
	static int TwoSwitches(int p, int q, int r, int s){
		if(q<=r)return 0;
		else if(p<=r && r<=q && q<=s)return q-r;
		else if(r<=p && q<=s)return q-p;
		else if(p<=r && s<=q)return s-r;
		else if(r<=p && p<=s && s<=q)return s-p;
		else return 0;
	}

	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();
		System.out.println(TwoSwitches(a, b, c, d));
	}
} Main
import java.util.*;
public class Main{
	static int TwoSwitches(int p, int q, int r, int s){
		if(q<=r)return 0;
		else if(p<=r && r<=q && q<=s)return q-r;
		else if(r<=p && q<=s)return q-p;
		else if(p<=r && s<=q)return s-r;
		else if(r<=p && p<=s && s<=q)return s-p;
		else return 0;
	}

	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();
		System.out.println(TwoSwitches(a, b, c, d));
	}
}