
import java.util.*;

public 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();
		
	    int time = 0;
		
	    if( A<=C && C<=B ) {
	    	if( B<=D ) {
	    		time = B-C;
	    	}else {
	    		time = D-C;
	    	}
	    }else if( C<A && A<=D ){
	    	if( D<=B ) {
	    		time = D-A;
	    	}else {
	    		time = B-A;
	    	}
	    }
	    
		System.out.println(time);
	}
} import java.util.*; util.* java public 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();
		
	    int time = 0;
		
	    if( A<=C && C<=B ) {
	    	if( B<=D ) {
	    		time = B-C;
	    	}else {
	    		time = D-C;
	    	}
	    }else if( C<A && A<=D ){
	    	if( D<=B ) {
	    		time = D-A;
	    	}else {
	    		time = B-A;
	    	}
	    }
	    
		System.out.println(time);
	}
} 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();
		
	    int time = 0;
		
	    if( A<=C && C<=B ) {
	    	if( B<=D ) {
	    		time = B-C;
	    	}else {
	    		time = D-C;
	    	}
	    }else if( C<A && A<=D ){
	    	if( D<=B ) {
	    		time = D-A;
	    	}else {
	    		time = B-A;
	    	}
	    }
	    
		System.out.println(time);
	} main {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		
	    int time = 0;
		
	    if( A<=C && C<=B ) {
	    	if( B<=D ) {
	    		time = B-C;
	    	}else {
	    		time = D-C;
	    	}
	    }else if( C<A && A<=D ){
	    	if( D<=B ) {
	    		time = D-A;
	    	}else {
	    		time = B-A;
	    	}
	    }
	    
		System.out.println(time);
	} 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 int time = 0; time 0 if( A<=C && C<=B ) {
	    	if( B<=D ) {
	    		time = B-C;
	    	}else {
	    		time = D-C;
	    	}
	    }else if( C<A && A<=D ){
	    	if( D<=B ) {
	    		time = D-A;
	    	}else {
	    		time = B-A;
	    	}
	    } A<=C && C<=B A<=C A C C<=B C B {
	    	if( B<=D ) {
	    		time = B-C;
	    	}else {
	    		time = D-C;
	    	}
	    } if( B<=D ) {
	    		time = B-C;
	    	}else {
	    		time = D-C;
	    	} B<=D B D {
	    		time = B-C;
	    	} time = B-C time B-C B C {
	    		time = D-C;
	    	} time = D-C time D-C D C if( C<A && A<=D ){
	    	if( D<=B ) {
	    		time = D-A;
	    	}else {
	    		time = B-A;
	    	}
	    } C<A && A<=D C<A C A A<=D A D {
	    	if( D<=B ) {
	    		time = D-A;
	    	}else {
	    		time = B-A;
	    	}
	    } if( D<=B ) {
	    		time = D-A;
	    	}else {
	    		time = B-A;
	    	} D<=B D B {
	    		time = D-A;
	    	} time = D-A time D-A D A {
	    		time = B-A;
	    	} time = B-A time B-A B A 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 = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		
	    int time = 0;
		
	    if( A<=C && C<=B ) {
	    	if( B<=D ) {
	    		time = B-C;
	    	}else {
	    		time = D-C;
	    	}
	    }else if( C<A && A<=D ){
	    	if( D<=B ) {
	    		time = D-A;
	    	}else {
	    		time = B-A;
	    	}
	    }
	    
		System.out.println(time);
	}
} public 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();
		
	    int time = 0;
		
	    if( A<=C && C<=B ) {
	    	if( B<=D ) {
	    		time = B-C;
	    	}else {
	    		time = D-C;
	    	}
	    }else if( C<A && A<=D ){
	    	if( D<=B ) {
	    		time = D-A;
	    	}else {
	    		time = B-A;
	    	}
	    }
	    
		System.out.println(time);
	}
} Main

import java.util.*;

public 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();
		
	    int time = 0;
		
	    if( A<=C && C<=B ) {
	    	if( B<=D ) {
	    		time = B-C;
	    	}else {
	    		time = D-C;
	    	}
	    }else if( C<A && A<=D ){
	    	if( D<=B ) {
	    		time = D-A;
	    	}else {
	    		time = B-A;
	    	}
	    }
	    
		System.out.println(time);
	}
}
