import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(),
            c = in.nextInt(), d = in.nextInt();
        
        if((c > b && d > b) || (a > d && b > d)){
            System.out.println(0);
            return;
        }
        int ans = 0;
        if(a > c){
            ans = d - a - Math.max(0, d - b);
        }else{
            ans = b - c - Math.max(0, b - d);
        }
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(),
            c = in.nextInt(), d = in.nextInt();
        
        if((c > b && d > b) || (a > d && b > d)){
            System.out.println(0);
            return;
        }
        int ans = 0;
        if(a > c){
            ans = d - a - Math.max(0, d - b);
        }else{
            ans = b - c - Math.max(0, b - d);
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(),
            c = in.nextInt(), d = in.nextInt();
        
        if((c > b && d > b) || (a > d && b > d)){
            System.out.println(0);
            return;
        }
        int ans = 0;
        if(a > c){
            ans = d - a - Math.max(0, d - b);
        }else{
            ans = b - c - Math.max(0, b - d);
        }
        System.out.println(ans);
    } main {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(),
            c = in.nextInt(), d = in.nextInt();
        
        if((c > b && d > b) || (a > d && b > d)){
            System.out.println(0);
            return;
        }
        int ans = 0;
        if(a > c){
            ans = d - a - Math.max(0, d - b);
        }else{
            ans = b - c - Math.max(0, b - d);
        }
        System.out.println(ans);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int a = in.nextInt() a in.nextInt() in.nextInt in b = in.nextInt() b in.nextInt() in.nextInt in c = in.nextInt() c in.nextInt() in.nextInt in d = in.nextInt(); d in.nextInt() in.nextInt in if((c > b && d > b) || (a > d && b > d)){
            System.out.println(0);
            return;
        } (c > b && d > b) || (a > d && b > d) (c > b && d > b) c > b c b d > b d b (a > d && b > d) a > d a d b > d b d {
            System.out.println(0);
            return;
        } System.out.println(0) System.out.println System.out System System.out 0 return; int ans = 0; ans 0 if(a > c){
            ans = d - a - Math.max(0, d - b);
        }else{
            ans = b - c - Math.max(0, b - d);
        } a > c a c {
            ans = d - a - Math.max(0, d - b);
        } ans = d - a - Math.max(0, d - b) ans d - a - Math.max(0, d - b) d - a - Math.max(0, d - b) d a Math.max(0, d - b) Math.max Math 0 d - b d b {
            ans = b - c - Math.max(0, b - d);
        } ans = b - c - Math.max(0, b - d) ans b - c - Math.max(0, b - d) b - c - Math.max(0, b - d) b c Math.max(0, b - d) Math.max Math 0 b - d b d System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(),
            c = in.nextInt(), d = in.nextInt();
        
        if((c > b && d > b) || (a > d && b > d)){
            System.out.println(0);
            return;
        }
        int ans = 0;
        if(a > c){
            ans = d - a - Math.max(0, d - b);
        }else{
            ans = b - c - Math.max(0, b - d);
        }
        System.out.println(ans);
    }
}