import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a, b, c, d;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		
		sc.close();
		
		int time = Math.min(d,  b);
		time -= Math.max(a, c);
		
		if(time < 0)time = 0;
		System.out.println(time);
		
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a, b, c, d;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		
		sc.close();
		
		int time = Math.min(d,  b);
		time -= Math.max(a, c);
		
		if(time < 0)time = 0;
		System.out.println(time);
		
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a, b, c, d;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		
		sc.close();
		
		int time = Math.min(d,  b);
		time -= Math.max(a, c);
		
		if(time < 0)time = 0;
		System.out.println(time);
		
	} main {
		Scanner sc = new Scanner(System.in);
		
		int a, b, c, d;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		
		sc.close();
		
		int time = Math.min(d,  b);
		time -= Math.max(a, c);
		
		if(time < 0)time = 0;
		System.out.println(time);
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a a b b c c d; d a = sc.nextInt() a sc.nextInt() sc.nextInt sc b = sc.nextInt() b sc.nextInt() sc.nextInt sc c = sc.nextInt() c sc.nextInt() sc.nextInt sc d = sc.nextInt() d sc.nextInt() sc.nextInt sc sc.close() sc.close sc int time = Math.min(d,  b); time Math.min(d,  b) Math.min Math d b time -= Math.max(a, c) time Math.max(a, c) Math.max Math a c if(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, b, c, d;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		
		sc.close();
		
		int time = Math.min(d,  b);
		time -= Math.max(a, c);
		
		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, b, c, d;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		
		sc.close();
		
		int time = Math.min(d,  b);
		time -= Math.max(a, c);
		
		if(time < 0)time = 0;
		System.out.println(time);
		
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a, b, c, d;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		
		sc.close();
		
		int time = Math.min(d,  b);
		time -= Math.max(a, c);
		
		if(time < 0)time = 0;
		System.out.println(time);
		
	}

}
