import java.util.Scanner;

class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int a, b, c, d;
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();
		d = scan.nextInt();
		
		if(a <= c && c <= b)
			if(b <= d)System.out.print(b-c);
			else System.out.print(d-c);
		else if(c <= a && a <= d)
			if(d <= b)System.out.print(d-a);
			else System.out.print(b-a);
		else System.out.print(0);
		
	}
} import java.util.Scanner; Scanner java.util class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int a, b, c, d;
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();
		d = scan.nextInt();
		
		if(a <= c && c <= b)
			if(b <= d)System.out.print(b-c);
			else System.out.print(d-c);
		else if(c <= a && a <= d)
			if(d <= b)System.out.print(d-a);
			else System.out.print(b-a);
		else System.out.print(0);
		
	}
} Main public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int a, b, c, d;
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();
		d = scan.nextInt();
		
		if(a <= c && c <= b)
			if(b <= d)System.out.print(b-c);
			else System.out.print(d-c);
		else if(c <= a && a <= d)
			if(d <= b)System.out.print(d-a);
			else System.out.print(b-a);
		else System.out.print(0);
		
	} main {

		Scanner scan = new Scanner(System.in);
		int a, b, c, d;
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();
		d = scan.nextInt();
		
		if(a <= c && c <= b)
			if(b <= d)System.out.print(b-c);
			else System.out.print(d-c);
		else if(c <= a && a <= d)
			if(d <= b)System.out.print(d-a);
			else System.out.print(b-a);
		else System.out.print(0);
		
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int a a b b c c d; d a = scan.nextInt() a scan.nextInt() scan.nextInt scan b = scan.nextInt() b scan.nextInt() scan.nextInt scan c = scan.nextInt() c scan.nextInt() scan.nextInt scan d = scan.nextInt() d scan.nextInt() scan.nextInt scan if(a <= c && c <= b)
			if(b <= d)System.out.print(b-c);
			else System.out.print(d-c);
		else if(c <= a && a <= d)
			if(d <= b)System.out.print(d-a);
			else System.out.print(b-a);
		else System.out.print(0); a <= c && c <= b a <= c a c c <= b c b if(b <= d)System.out.print(b-c);
			else System.out.print(d-c); b <= d b d System.out.print(b-c) System.out.print System.out System System.out b-c b c System.out.print(d-c) System.out.print System.out System System.out d-c d c if(c <= a && a <= d)
			if(d <= b)System.out.print(d-a);
			else System.out.print(b-a);
		else System.out.print(0); c <= a && a <= d c <= a c a a <= d a d if(d <= b)System.out.print(d-a);
			else System.out.print(b-a); d <= b d b System.out.print(d-a) System.out.print System.out System System.out d-a d a System.out.print(b-a) System.out.print System.out System System.out b-a b a System.out.print(0) System.out.print System.out System System.out 0 String args[] args
import java.util.Scanner;

class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int a, b, c, d;
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();
		d = scan.nextInt();
		
		if(a <= c && c <= b)
			if(b <= d)System.out.print(b-c);
			else System.out.print(d-c);
		else if(c <= a && a <= d)
			if(d <= b)System.out.print(d-a);
			else System.out.print(b-a);
		else System.out.print(0);
		
	}
}