import java.io.*;
import java.util.*;
 
public class Main {
    public static int MAXN = 1600;
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a=cin.nextInt(),b=cin.nextInt(),c=cin.nextInt(),d=cin.nextInt();
        int ans=0;
        for(int i=a;i<b;i++){
        	if(i>=c&&i<d){
        		ans++;
        	}
        }
        out.println(ans);
        out.flush();
        out.close();
        cin.close();
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    public static int MAXN = 1600;
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a=cin.nextInt(),b=cin.nextInt(),c=cin.nextInt(),d=cin.nextInt();
        int ans=0;
        for(int i=a;i<b;i++){
        	if(i>=c&&i<d){
        		ans++;
        	}
        }
        out.println(ans);
        out.flush();
        out.close();
        cin.close();
    }
} Main public static int MAXN = 1600; MAXN 1600 public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a=cin.nextInt(),b=cin.nextInt(),c=cin.nextInt(),d=cin.nextInt();
        int ans=0;
        for(int i=a;i<b;i++){
        	if(i>=c&&i<d){
        		ans++;
        	}
        }
        out.println(ans);
        out.flush();
        out.close();
        cin.close();
    } main {
        Scanner cin = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a=cin.nextInt(),b=cin.nextInt(),c=cin.nextInt(),d=cin.nextInt();
        int ans=0;
        for(int i=a;i<b;i++){
        	if(i>=c&&i<d){
        		ans++;
        	}
        }
        out.println(ans);
        out.flush();
        out.close();
        cin.close();
    } Scanner cin = new Scanner(System.in); cin new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int a=cin.nextInt() a cin.nextInt() cin.nextInt cin b=cin.nextInt() b cin.nextInt() cin.nextInt cin c=cin.nextInt() c cin.nextInt() cin.nextInt cin d=cin.nextInt(); d cin.nextInt() cin.nextInt cin int ans=0; ans 0 for(int i=a;i<b;i++){
        	if(i>=c&&i<d){
        		ans++;
        	}
        } int i=a; int i=a; i a i<b i b i++ i++ i {
        	if(i>=c&&i<d){
        		ans++;
        	}
        } {
        	if(i>=c&&i<d){
        		ans++;
        	}
        } if(i>=c&&i<d){
        		ans++;
        	} i>=c&&i<d i>=c i c i<d i d {
        		ans++;
        	} ans++ ans out.println(ans) out.println out ans out.flush() out.flush out out.close() out.close out cin.close() cin.close cin String[] args args public class Main {
    public static int MAXN = 1600;
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a=cin.nextInt(),b=cin.nextInt(),c=cin.nextInt(),d=cin.nextInt();
        int ans=0;
        for(int i=a;i<b;i++){
        	if(i>=c&&i<d){
        		ans++;
        	}
        }
        out.println(ans);
        out.flush();
        out.close();
        cin.close();
    }
} public class Main {
    public static int MAXN = 1600;
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a=cin.nextInt(),b=cin.nextInt(),c=cin.nextInt(),d=cin.nextInt();
        int ans=0;
        for(int i=a;i<b;i++){
        	if(i>=c&&i<d){
        		ans++;
        	}
        }
        out.println(ans);
        out.flush();
        out.close();
        cin.close();
    }
} Main
import java.io.*;
import java.util.*;
 
public class Main {
    public static int MAXN = 1600;
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a=cin.nextInt(),b=cin.nextInt(),c=cin.nextInt(),d=cin.nextInt();
        int ans=0;
        for(int i=a;i<b;i++){
        	if(i>=c&&i<d){
        		ans++;
        	}
        }
        out.println(ans);
        out.flush();
        out.close();
        cin.close();
    }
}