import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int a = sc.nextInt();// Alice A秒
		int b = sc.nextInt();// Alice B秒
		int c = sc.nextInt();// Bob C秒
		int d = sc.nextInt();// Bob D秒

		// 計算
		int t = 0;

		// abcd
		if(b <= c) t = 0;
		// acbd
		if(a <= c && c <= b && b <= d) t = b - c;
		// cabd
		if(c <= a && b <= d) t = b - a;
		// acdb
		if(a <= c && d <= b) t = d - c;
		// cadb
		if(c <= a && a <= d && d <= b) t = d - a;
		// cdab
		if(d <= a) t = 0;

		// 出力
		System.out.println(t);

	}
}

 import java.util.*; util.* java import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int a = sc.nextInt();// Alice A秒
		int b = sc.nextInt();// Alice B秒
		int c = sc.nextInt();// Bob C秒
		int d = sc.nextInt();// Bob D秒

		// 計算
		int t = 0;

		// abcd
		if(b <= c) t = 0;
		// acbd
		if(a <= c && c <= b && b <= d) t = b - c;
		// cabd
		if(c <= a && b <= d) t = b - a;
		// acdb
		if(a <= c && d <= b) t = d - c;
		// cadb
		if(c <= a && a <= d && d <= b) t = d - a;
		// cdab
		if(d <= a) t = 0;

		// 出力
		System.out.println(t);

	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int a = sc.nextInt();// Alice A秒
		int b = sc.nextInt();// Alice B秒
		int c = sc.nextInt();// Bob C秒
		int d = sc.nextInt();// Bob D秒

		// 計算
		int t = 0;

		// abcd
		if(b <= c) t = 0;
		// acbd
		if(a <= c && c <= b && b <= d) t = b - c;
		// cabd
		if(c <= a && b <= d) t = b - a;
		// acdb
		if(a <= c && d <= b) t = d - c;
		// cadb
		if(c <= a && a <= d && d <= b) t = d - a;
		// cdab
		if(d <= a) t = 0;

		// 出力
		System.out.println(t);

	} main {
		Scanner sc = new Scanner(System.in);

		// 入力
		int a = sc.nextInt();// Alice A秒
		int b = sc.nextInt();// Alice B秒
		int c = sc.nextInt();// Bob C秒
		int d = sc.nextInt();// Bob D秒

		// 計算
		int t = 0;

		// abcd
		if(b <= c) t = 0;
		// acbd
		if(a <= c && c <= b && b <= d) t = b - c;
		// cabd
		if(c <= a && b <= d) t = b - a;
		// acdb
		if(a <= c && d <= b) t = d - c;
		// cadb
		if(c <= a && a <= d && d <= b) t = d - a;
		// cdab
		if(d <= a) t = 0;

		// 出力
		System.out.println(t);

	} 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 int t = 0; t 0 if(b <= c) t = 0; b <= c b c t = 0 t 0 if(a <= c && c <= b && b <= d) t = b - c; a <= c && c <= b && b <= d a <= c && c <= b && b <= d a <= c a c c <= b c b b <= d b d t = b - c t b - c b c if(c <= a && b <= d) t = b - a; c <= a && b <= d c <= a c a b <= d b d t = b - a t b - a b a if(a <= c && d <= b) t = d - c; a <= c && d <= b a <= c a c d <= b d b t = d - c t d - c d c if(c <= a && a <= d && d <= b) t = d - a; c <= a && a <= d && d <= b c <= a && a <= d && d <= b c <= a c a a <= d a d d <= b d b t = d - a t d - a d a if(d <= a) t = 0; d <= a d a t = 0 t 0 System.out.println(t) System.out.println System.out System System.out t String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int a = sc.nextInt();// Alice A秒
		int b = sc.nextInt();// Alice B秒
		int c = sc.nextInt();// Bob C秒
		int d = sc.nextInt();// Bob D秒

		// 計算
		int t = 0;

		// abcd
		if(b <= c) t = 0;
		// acbd
		if(a <= c && c <= b && b <= d) t = b - c;
		// cabd
		if(c <= a && b <= d) t = b - a;
		// acdb
		if(a <= c && d <= b) t = d - c;
		// cadb
		if(c <= a && a <= d && d <= b) t = d - a;
		// cdab
		if(d <= a) t = 0;

		// 出力
		System.out.println(t);

	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int a = sc.nextInt();// Alice A秒
		int b = sc.nextInt();// Alice B秒
		int c = sc.nextInt();// Bob C秒
		int d = sc.nextInt();// Bob D秒

		// 計算
		int t = 0;

		// abcd
		if(b <= c) t = 0;
		// acbd
		if(a <= c && c <= b && b <= d) t = b - c;
		// cabd
		if(c <= a && b <= d) t = b - a;
		// acdb
		if(a <= c && d <= b) t = d - c;
		// cadb
		if(c <= a && a <= d && d <= b) t = d - a;
		// cdab
		if(d <= a) t = 0;

		// 出力
		System.out.println(t);

	}
} Main
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int a = sc.nextInt();// Alice A秒
		int b = sc.nextInt();// Alice B秒
		int c = sc.nextInt();// Bob C秒
		int d = sc.nextInt();// Bob D秒

		// 計算
		int t = 0;

		// abcd
		if(b <= c) t = 0;
		// acbd
		if(a <= c && c <= b && b <= d) t = b - c;
		// cabd
		if(c <= a && b <= d) t = b - a;
		// acdb
		if(a <= c && d <= b) t = d - c;
		// cadb
		if(c <= a && a <= d && d <= b) t = d - a;
		// cdab
		if(d <= a) t = 0;

		// 出力
		System.out.println(t);

	}
}


