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