import 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();
		
		int time;
		
		if(a<=c) {
			time = Math.min(b-c, d-c);
		}else {
			time = Math.min(b-a, d-a);
		}
		
		if(time<0) {
			time = 0;
		}
		System.out.println(time);
	}

} import java.util.*; util.* java 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();
		
		int time;
		
		if(a<=c) {
			time = Math.min(b-c, d-c);
		}else {
			time = Math.min(b-a, d-a);
		}
		
		if(time<0) {
			time = 0;
		}
		System.out.println(time);
	}

} 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();
		
		int time;
		
		if(a<=c) {
			time = Math.min(b-c, d-c);
		}else {
			time = Math.min(b-a, d-a);
		}
		
		if(time<0) {
			time = 0;
		}
		System.out.println(time);
	} 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();
		
		int time;
		
		if(a<=c) {
			time = Math.min(b-c, d-c);
		}else {
			time = Math.min(b-a, d-a);
		}
		
		if(time<0) {
			time = 0;
		}
		System.out.println(time);
	} 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 int time; time if(a<=c) {
			time = Math.min(b-c, d-c);
		}else {
			time = Math.min(b-a, d-a);
		} a<=c a c {
			time = Math.min(b-c, d-c);
		} time = Math.min(b-c, d-c) time Math.min(b-c, d-c) Math.min Math b-c b c d-c d c {
			time = Math.min(b-a, d-a);
		} time = Math.min(b-a, d-a) time Math.min(b-a, d-a) Math.min Math b-a b a d-a d a if(time<0) {
			time = 0;
		} time<0 time 0 {
			time = 0;
		} time = 0 time 0 System.out.println(time) System.out.println System.out System System.out time String[] args args 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();
		
		int time;
		
		if(a<=c) {
			time = Math.min(b-c, d-c);
		}else {
			time = Math.min(b-a, d-a);
		}
		
		if(time<0) {
			time = 0;
		}
		System.out.println(time);
	}

} 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();
		
		int time;
		
		if(a<=c) {
			time = Math.min(b-c, d-c);
		}else {
			time = Math.min(b-a, d-a);
		}
		
		if(time<0) {
			time = 0;
		}
		System.out.println(time);
	}

} Main
import 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();
		
		int time;
		
		if(a<=c) {
			time = Math.min(b-c, d-c);
		}else {
			time = Math.min(b-a, d-a);
		}
		
		if(time<0) {
			time = 0;
		}
		System.out.println(time);
	}

}