import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int a=s.nextInt();
        int b=s.nextInt();
        int c=s.nextInt();
        int d=s.nextInt();
        int[] x=new int[100000];
        int i,count=0;
        for(i=0;i<100000;i++)x[i]=0;
        for(i=a;i<b;i++)x[i]++;
        for(i=c;i<d;i++)x[i]++;
        for(i=0;i<100000;i++){
            if(x[i]==2)count++;
        }
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int a=s.nextInt();
        int b=s.nextInt();
        int c=s.nextInt();
        int d=s.nextInt();
        int[] x=new int[100000];
        int i,count=0;
        for(i=0;i<100000;i++)x[i]=0;
        for(i=a;i<b;i++)x[i]++;
        for(i=c;i<d;i++)x[i]++;
        for(i=0;i<100000;i++){
            if(x[i]==2)count++;
        }
        System.out.println(count);
    }
} Main public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int a=s.nextInt();
        int b=s.nextInt();
        int c=s.nextInt();
        int d=s.nextInt();
        int[] x=new int[100000];
        int i,count=0;
        for(i=0;i<100000;i++)x[i]=0;
        for(i=a;i<b;i++)x[i]++;
        for(i=c;i<d;i++)x[i]++;
        for(i=0;i<100000;i++){
            if(x[i]==2)count++;
        }
        System.out.println(count);
    } main {
        Scanner s=new Scanner(System.in);
        int a=s.nextInt();
        int b=s.nextInt();
        int c=s.nextInt();
        int d=s.nextInt();
        int[] x=new int[100000];
        int i,count=0;
        for(i=0;i<100000;i++)x[i]=0;
        for(i=a;i<b;i++)x[i]++;
        for(i=c;i<d;i++)x[i]++;
        for(i=0;i<100000;i++){
            if(x[i]==2)count++;
        }
        System.out.println(count);
    } Scanner s=new Scanner(System.in); s new Scanner(System.in) int a=s.nextInt(); a s.nextInt() s.nextInt s int b=s.nextInt(); b s.nextInt() s.nextInt s int c=s.nextInt(); c s.nextInt() s.nextInt s int d=s.nextInt(); d s.nextInt() s.nextInt s int[] x=new int[100000]; x new int[100000] 100000 int i i count=0; count 0 for(i=0;i<100000;i++)x[i]=0; i=0; i=0 i 0 i<100000 i 100000 i++ i++ i x[i]=0; x[i]=0 x[i] x i 0 for(i=a;i<b;i++)x[i]++; i=a; i=a i a i<b i b i++ i++ i x[i]++; x[i]++ x[i] x i for(i=c;i<d;i++)x[i]++; i=c; i=c i c i<d i d i++ i++ i x[i]++; x[i]++ x[i] x i for(i=0;i<100000;i++){
            if(x[i]==2)count++;
        } i=0; i=0 i 0 i<100000 i 100000 i++ i++ i {
            if(x[i]==2)count++;
        } {
            if(x[i]==2)count++;
        } if(x[i]==2)count++; x[i]==2 x[i] x i 2 count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int a=s.nextInt();
        int b=s.nextInt();
        int c=s.nextInt();
        int d=s.nextInt();
        int[] x=new int[100000];
        int i,count=0;
        for(i=0;i<100000;i++)x[i]=0;
        for(i=a;i<b;i++)x[i]++;
        for(i=c;i<d;i++)x[i]++;
        for(i=0;i<100000;i++){
            if(x[i]==2)count++;
        }
        System.out.println(count);
    }
} public class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int a=s.nextInt();
        int b=s.nextInt();
        int c=s.nextInt();
        int d=s.nextInt();
        int[] x=new int[100000];
        int i,count=0;
        for(i=0;i<100000;i++)x[i]=0;
        for(i=a;i<b;i++)x[i]++;
        for(i=c;i<d;i++)x[i]++;
        for(i=0;i<100000;i++){
            if(x[i]==2)count++;
        }
        System.out.println(count);
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int a=s.nextInt();
        int b=s.nextInt();
        int c=s.nextInt();
        int d=s.nextInt();
        int[] x=new int[100000];
        int i,count=0;
        for(i=0;i<100000;i++)x[i]=0;
        for(i=a;i<b;i++)x[i]++;
        for(i=c;i<d;i++)x[i]++;
        for(i=0;i<100000;i++){
            if(x[i]==2)count++;
        }
        System.out.println(count);
    }
}