import java.util.Scanner;

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

		if(b <= d){
			if(c <= b){
				if(a >= c){
					System.out.println(b-a);

				}else{
					System.out.println(b-c);
				}
			}else{
				System.out.println(0);

			}
		}else{				//b>d
			if(d >= a){
				if(a <= c){
					System.out.println(d-c);
				}else{
					System.out.println(d-a);

				}

			}else{
				System.out.println(0);

			}
		}

	}
} import java.util.Scanner; Scanner java.util 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();

		if(b <= d){
			if(c <= b){
				if(a >= c){
					System.out.println(b-a);

				}else{
					System.out.println(b-c);
				}
			}else{
				System.out.println(0);

			}
		}else{				//b>d
			if(d >= a){
				if(a <= c){
					System.out.println(d-c);
				}else{
					System.out.println(d-a);

				}

			}else{
				System.out.println(0);

			}
		}

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

		if(b <= d){
			if(c <= b){
				if(a >= c){
					System.out.println(b-a);

				}else{
					System.out.println(b-c);
				}
			}else{
				System.out.println(0);

			}
		}else{				//b>d
			if(d >= a){
				if(a <= c){
					System.out.println(d-c);
				}else{
					System.out.println(d-a);

				}

			}else{
				System.out.println(0);

			}
		}

	} main {

		Scanner sc = new Scanner(System.in);			//文字の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		if(b <= d){
			if(c <= b){
				if(a >= c){
					System.out.println(b-a);

				}else{
					System.out.println(b-c);
				}
			}else{
				System.out.println(0);

			}
		}else{				//b>d
			if(d >= a){
				if(a <= c){
					System.out.println(d-c);
				}else{
					System.out.println(d-a);

				}

			}else{
				System.out.println(0);

			}
		}

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

				}else{
					System.out.println(b-c);
				}
			}else{
				System.out.println(0);

			}
		}else{				//b>d
			if(d >= a){
				if(a <= c){
					System.out.println(d-c);
				}else{
					System.out.println(d-a);

				}

			}else{
				System.out.println(0);

			}
		} b <= d b d {
			if(c <= b){
				if(a >= c){
					System.out.println(b-a);

				}else{
					System.out.println(b-c);
				}
			}else{
				System.out.println(0);

			}
		} if(c <= b){
				if(a >= c){
					System.out.println(b-a);

				}else{
					System.out.println(b-c);
				}
			}else{
				System.out.println(0);

			} c <= b c b {
				if(a >= c){
					System.out.println(b-a);

				}else{
					System.out.println(b-c);
				}
			} if(a >= c){
					System.out.println(b-a);

				}else{
					System.out.println(b-c);
				} a >= c a c {
					System.out.println(b-a);

				} System.out.println(b-a) System.out.println System.out System System.out b-a b a {
					System.out.println(b-c);
				} System.out.println(b-c) System.out.println System.out System System.out b-c b c {
				System.out.println(0);

			} System.out.println(0) System.out.println System.out System System.out 0 {				//b>d
			if(d >= a){
				if(a <= c){
					System.out.println(d-c);
				}else{
					System.out.println(d-a);

				}

			}else{
				System.out.println(0);

			}
		} if(d >= a){
				if(a <= c){
					System.out.println(d-c);
				}else{
					System.out.println(d-a);

				}

			}else{
				System.out.println(0);

			} d >= a d a {
				if(a <= c){
					System.out.println(d-c);
				}else{
					System.out.println(d-a);

				}

			} if(a <= c){
					System.out.println(d-c);
				}else{
					System.out.println(d-a);

				} a <= c a c {
					System.out.println(d-c);
				} System.out.println(d-c) System.out.println System.out System System.out d-c d c {
					System.out.println(d-a);

				} System.out.println(d-a) System.out.println System.out System System.out d-a d a {
				System.out.println(0);

			} System.out.println(0) System.out.println System.out System System.out 0 String[] args args
import java.util.Scanner;

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

		if(b <= d){
			if(c <= b){
				if(a >= c){
					System.out.println(b-a);

				}else{
					System.out.println(b-c);
				}
			}else{
				System.out.println(0);

			}
		}else{				//b>d
			if(d >= a){
				if(a <= c){
					System.out.println(d-c);
				}else{
					System.out.println(d-a);

				}

			}else{
				System.out.println(0);

			}
		}

	}
}