import 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(a >= c) {
		if(a >= d) {
			System.out.println(0);
		} else if(a <= d && b >= d) {
			System.out.println(d - a);
		} else if(b <= d) {
			System.out.println(b - a);
		}
	} else {
		if(c >= b) {
			System.out.println(0);
		} else if(c <= b && b <= d) {
			System.out.println(b- c);
		} else if(b >= d) {
			System.out.println(d - c);
		}
	}
}
} import java.util.*; util.* java 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(a >= c) {
		if(a >= d) {
			System.out.println(0);
		} else if(a <= d && b >= d) {
			System.out.println(d - a);
		} else if(b <= d) {
			System.out.println(b - a);
		}
	} else {
		if(c >= b) {
			System.out.println(0);
		} else if(c <= b && b <= d) {
			System.out.println(b- c);
		} else if(b >= d) {
			System.out.println(d - c);
		}
	}
}
} 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(a >= c) {
		if(a >= d) {
			System.out.println(0);
		} else if(a <= d && b >= d) {
			System.out.println(d - a);
		} else if(b <= d) {
			System.out.println(b - a);
		}
	} else {
		if(c >= b) {
			System.out.println(0);
		} else if(c <= b && b <= d) {
			System.out.println(b- c);
		} else if(b >= d) {
			System.out.println(d - c);
		}
	}
} main {
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	int d = sc.nextInt();
	if(a >= c) {
		if(a >= d) {
			System.out.println(0);
		} else if(a <= d && b >= d) {
			System.out.println(d - a);
		} else if(b <= d) {
			System.out.println(b - a);
		}
	} else {
		if(c >= b) {
			System.out.println(0);
		} else if(c <= b && b <= d) {
			System.out.println(b- c);
		} else if(b >= d) {
			System.out.println(d - c);
		}
	}
} 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(a >= c) {
		if(a >= d) {
			System.out.println(0);
		} else if(a <= d && b >= d) {
			System.out.println(d - a);
		} else if(b <= d) {
			System.out.println(b - a);
		}
	} else {
		if(c >= b) {
			System.out.println(0);
		} else if(c <= b && b <= d) {
			System.out.println(b- c);
		} else if(b >= d) {
			System.out.println(d - c);
		}
	} a >= c a c {
		if(a >= d) {
			System.out.println(0);
		} else if(a <= d && b >= d) {
			System.out.println(d - a);
		} else if(b <= d) {
			System.out.println(b - a);
		}
	} if(a >= d) {
			System.out.println(0);
		} else if(a <= d && b >= d) {
			System.out.println(d - a);
		} else if(b <= d) {
			System.out.println(b - a);
		} a >= d a d {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 if(a <= d && b >= d) {
			System.out.println(d - a);
		} else if(b <= d) {
			System.out.println(b - a);
		} a <= d && b >= d a <= d a d b >= d b d {
			System.out.println(d - a);
		} System.out.println(d - a) System.out.println System.out System System.out d - a d a if(b <= d) {
			System.out.println(b - a);
		} b <= d b d {
			System.out.println(b - a);
		} System.out.println(b - a) System.out.println System.out System System.out b - a b a {
		if(c >= b) {
			System.out.println(0);
		} else if(c <= b && b <= d) {
			System.out.println(b- c);
		} else if(b >= d) {
			System.out.println(d - c);
		}
	} if(c >= b) {
			System.out.println(0);
		} else if(c <= b && b <= d) {
			System.out.println(b- c);
		} else if(b >= d) {
			System.out.println(d - c);
		} c >= b c b {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 if(c <= b && b <= d) {
			System.out.println(b- c);
		} else if(b >= d) {
			System.out.println(d - c);
		} c <= b && b <= d c <= b c b b <= d b d {
			System.out.println(b- c);
		} System.out.println(b- c) System.out.println System.out System System.out b- c b c if(b >= d) {
			System.out.println(d - c);
		} b >= d b d {
			System.out.println(d - c);
		} System.out.println(d - c) System.out.println System.out System System.out d - c d c String[] args args
import 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(a >= c) {
		if(a >= d) {
			System.out.println(0);
		} else if(a <= d && b >= d) {
			System.out.println(d - a);
		} else if(b <= d) {
			System.out.println(b - a);
		}
	} else {
		if(c >= b) {
			System.out.println(0);
		} else if(c <= b && b <= d) {
			System.out.println(b- c);
		} else if(b >= d) {
			System.out.println(d - c);
		}
	}
}
}
