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 diff = 0;
	
	/* aliceが早い */
	if(a < c){
	    diff = Math.min(b-c,d-c);
	}
	/* bobが早い */
	else if(c < a){
	    diff = Math.min(b-a,d-a);
	}
	/* 同時に押した */
	else{
	    diff = Math.min(b,d)-a;
	}

	if(diff < 0){
	    System.out.println(0);
	}else{
	    System.out.println(diff);
	}
    }
} 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 diff = 0;
	
	/* aliceが早い */
	if(a < c){
	    diff = Math.min(b-c,d-c);
	}
	/* bobが早い */
	else if(c < a){
	    diff = Math.min(b-a,d-a);
	}
	/* 同時に押した */
	else{
	    diff = Math.min(b,d)-a;
	}

	if(diff < 0){
	    System.out.println(0);
	}else{
	    System.out.println(diff);
	}
    }
} 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 diff = 0;
	
	/* aliceが早い */
	if(a < c){
	    diff = Math.min(b-c,d-c);
	}
	/* bobが早い */
	else if(c < a){
	    diff = Math.min(b-a,d-a);
	}
	/* 同時に押した */
	else{
	    diff = Math.min(b,d)-a;
	}

	if(diff < 0){
	    System.out.println(0);
	}else{
	    System.out.println(diff);
	}
    } main {
	Scanner scan = new Scanner(System.in);

	int a = scan.nextInt();
	int b = scan.nextInt();
	int c = scan.nextInt();
	int d = scan.nextInt();
	int diff = 0;
	
	/* aliceが早い */
	if(a < c){
	    diff = Math.min(b-c,d-c);
	}
	/* bobが早い */
	else if(c < a){
	    diff = Math.min(b-a,d-a);
	}
	/* 同時に押した */
	else{
	    diff = Math.min(b,d)-a;
	}

	if(diff < 0){
	    System.out.println(0);
	}else{
	    System.out.println(diff);
	}
    } 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 diff = 0; diff 0 if(a < c){
	    diff = Math.min(b-c,d-c);
	}
	/* bobが早い */
	else if(c < a){
	    diff = Math.min(b-a,d-a);
	}
	/* 同時に押した */
	else{
	    diff = Math.min(b,d)-a;
	} a < c a c {
	    diff = Math.min(b-c,d-c);
	} diff = Math.min(b-c,d-c) diff Math.min(b-c,d-c) Math.min Math b-c b c d-c d c if(c < a){
	    diff = Math.min(b-a,d-a);
	}
	/* 同時に押した */
	else{
	    diff = Math.min(b,d)-a;
	} c < a c a {
	    diff = Math.min(b-a,d-a);
	} diff = Math.min(b-a,d-a) diff Math.min(b-a,d-a) Math.min Math b-a b a d-a d a {
	    diff = Math.min(b,d)-a;
	} diff = Math.min(b,d)-a diff Math.min(b,d)-a Math.min(b,d) Math.min Math b d a if(diff < 0){
	    System.out.println(0);
	}else{
	    System.out.println(diff);
	} diff < 0 diff 0 {
	    System.out.println(0);
	} System.out.println(0) System.out.println System.out System System.out 0 {
	    System.out.println(diff);
	} System.out.println(diff) System.out.println System.out System System.out diff 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 diff = 0;
	
	/* aliceが早い */
	if(a < c){
	    diff = Math.min(b-c,d-c);
	}
	/* bobが早い */
	else if(c < a){
	    diff = Math.min(b-a,d-a);
	}
	/* 同時に押した */
	else{
	    diff = Math.min(b,d)-a;
	}

	if(diff < 0){
	    System.out.println(0);
	}else{
	    System.out.println(diff);
	}
    }
} 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 diff = 0;
	
	/* aliceが早い */
	if(a < c){
	    diff = Math.min(b-c,d-c);
	}
	/* bobが早い */
	else if(c < a){
	    diff = Math.min(b-a,d-a);
	}
	/* 同時に押した */
	else{
	    diff = Math.min(b,d)-a;
	}

	if(diff < 0){
	    System.out.println(0);
	}else{
	    System.out.println(diff);
	}
    }
} 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 diff = 0;
	
	/* aliceが早い */
	if(a < c){
	    diff = Math.min(b-c,d-c);
	}
	/* bobが早い */
	else if(c < a){
	    diff = Math.min(b-a,d-a);
	}
	/* 同時に押した */
	else{
	    diff = Math.min(b,d)-a;
	}

	if(diff < 0){
	    System.out.println(0);
	}else{
	    System.out.println(diff);
	}
    }
}
