import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		int ans = 0;

		if(b <= c || d <= a){
			ans = 0;
		}
		else if(c <= a && b <= d){
			ans = b - a;
		}
		else if(a <= c && d <= b){
			ans = d - c;
		}
		else if( a <= c && c <= b && b <= d){
			ans = b - c;
		}
		else if( c <= a && a <= d && d <= b){
			ans = d-a;
		}
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		int ans = 0;

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

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

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

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

		if(b <= c || d <= a){
			ans = 0;
		}
		else if(c <= a && b <= d){
			ans = b - a;
		}
		else if(a <= c && d <= b){
			ans = d - c;
		}
		else if( a <= c && c <= b && b <= d){
			ans = b - c;
		}
		else if( c <= a && a <= d && d <= b){
			ans = d-a;
		}
		System.out.println(ans);
	}
} Main
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		int ans = 0;

		if(b <= c || d <= a){
			ans = 0;
		}
		else if(c <= a && b <= d){
			ans = b - a;
		}
		else if(a <= c && d <= b){
			ans = d - c;
		}
		else if( a <= c && c <= b && b <= d){
			ans = b - c;
		}
		else if( c <= a && a <= d && d <= b){
			ans = d-a;
		}
		System.out.println(ans);
	}
}