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();

		Interval inter1 = new Interval(A, B);
		Interval inter2 = new Interval(C, D);

		Interval sect = Interval.GetIntersection(inter1, inter2);
		if(sect == null){
			sect = new Interval(0,0);
		}
		int ans = sect.GetLength();

		System.out.println(ans);
	}
}


class Interval{
	int Start;
	int End;

	Interval(int s, int e){
		Start = s;
		End = e;
	}

	static Interval GetIntersection(Interval i1, Interval i2){
		if(i1.Start > i2.Start){
			return GetIntersection(i2, i1);
		}
		if(i1.End < i2.Start){
			return null;
		}
		return new Interval(i2.Start, Math.min(i1.End, i2.End));

	}

	int GetLength(){
		return End - Start;
	}
} 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();

		Interval inter1 = new Interval(A, B);
		Interval inter2 = new Interval(C, D);

		Interval sect = Interval.GetIntersection(inter1, inter2);
		if(sect == null){
			sect = new Interval(0,0);
		}
		int ans = sect.GetLength();

		System.out.println(ans);
	}
} 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();

		Interval inter1 = new Interval(A, B);
		Interval inter2 = new Interval(C, D);

		Interval sect = Interval.GetIntersection(inter1, inter2);
		if(sect == null){
			sect = new Interval(0,0);
		}
		int ans = sect.GetLength();

		System.out.println(ans);
	} 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();

		Interval inter1 = new Interval(A, B);
		Interval inter2 = new Interval(C, D);

		Interval sect = Interval.GetIntersection(inter1, inter2);
		if(sect == null){
			sect = new Interval(0,0);
		}
		int ans = sect.GetLength();

		System.out.println(ans);
	} 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 Interval inter1 = new Interval(A, B); inter1 new Interval(A, B) Interval inter2 = new Interval(C, D); inter2 new Interval(C, D) Interval sect = Interval.GetIntersection(inter1, inter2); sect Interval.GetIntersection(inter1, inter2) Interval.GetIntersection Interval inter1 inter2 if(sect == null){
			sect = new Interval(0,0);
		} sect == null sect null {
			sect = new Interval(0,0);
		} sect = new Interval(0,0) sect new Interval(0,0) int ans = sect.GetLength(); ans sect.GetLength() sect.GetLength sect System.out.println(ans) System.out.println System.out System System.out ans String[] args args class Interval{
	int Start;
	int End;

	Interval(int s, int e){
		Start = s;
		End = e;
	}

	static Interval GetIntersection(Interval i1, Interval i2){
		if(i1.Start > i2.Start){
			return GetIntersection(i2, i1);
		}
		if(i1.End < i2.Start){
			return null;
		}
		return new Interval(i2.Start, Math.min(i1.End, i2.End));

	}

	int GetLength(){
		return End - Start;
	}
} Interval int Start; Start int End; End Interval(int s, int e){
		Start = s;
		End = e;
	} Interval {
		Start = s;
		End = e;
	} Start = s Start s End = e End e int s s int e e static Interval GetIntersection(Interval i1, Interval i2){
		if(i1.Start > i2.Start){
			return GetIntersection(i2, i1);
		}
		if(i1.End < i2.Start){
			return null;
		}
		return new Interval(i2.Start, Math.min(i1.End, i2.End));

	} GetIntersection {
		if(i1.Start > i2.Start){
			return GetIntersection(i2, i1);
		}
		if(i1.End < i2.Start){
			return null;
		}
		return new Interval(i2.Start, Math.min(i1.End, i2.End));

	} if(i1.Start > i2.Start){
			return GetIntersection(i2, i1);
		} i1.Start > i2.Start i1.Start i1 i1.Start i2.Start i2 i2.Start {
			return GetIntersection(i2, i1);
		} return GetIntersection(i2, i1); GetIntersection(i2, i1) GetIntersection i2 i1 if(i1.End < i2.Start){
			return null;
		} i1.End < i2.Start i1.End i1 i1.End i2.Start i2 i2.Start {
			return null;
		} return null; null return new Interval(i2.Start, Math.min(i1.End, i2.End)); new Interval(i2.Start, Math.min(i1.End, i2.End)) Interval i1 i1 Interval i2 i2 int GetLength(){
		return End - Start;
	} GetLength {
		return End - Start;
	} return End - Start; End - Start End Start 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();

		Interval inter1 = new Interval(A, B);
		Interval inter2 = new Interval(C, D);

		Interval sect = Interval.GetIntersection(inter1, inter2);
		if(sect == null){
			sect = new Interval(0,0);
		}
		int ans = sect.GetLength();

		System.out.println(ans);
	}
} 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();

		Interval inter1 = new Interval(A, B);
		Interval inter2 = new Interval(C, D);

		Interval sect = Interval.GetIntersection(inter1, inter2);
		if(sect == null){
			sect = new Interval(0,0);
		}
		int ans = sect.GetLength();

		System.out.println(ans);
	}
} 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();

		Interval inter1 = new Interval(A, B);
		Interval inter2 = new Interval(C, D);

		Interval sect = Interval.GetIntersection(inter1, inter2);
		if(sect == null){
			sect = new Interval(0,0);
		}
		int ans = sect.GetLength();

		System.out.println(ans);
	}
}


class Interval{
	int Start;
	int End;

	Interval(int s, int e){
		Start = s;
		End = e;
	}

	static Interval GetIntersection(Interval i1, Interval i2){
		if(i1.Start > i2.Start){
			return GetIntersection(i2, i1);
		}
		if(i1.End < i2.Start){
			return null;
		}
		return new Interval(i2.Start, Math.min(i1.End, i2.End));

	}

	int GetLength(){
		return End - Start;
	}
}
