import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a, b, c, d, ans = 0;
        a = scan.nextInt();
        b = scan.nextInt();
        c = scan.nextInt();
        d = scan.nextInt();

        if(a <= c){
            if(b > c){
                if(b <= d) {
                    ans = b - c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d > a){
                if(d <= b) {
                    ans = d - a;
                }else{
                    ans = b - a;
                }
            }
        }

        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a, b, c, d, ans = 0;
        a = scan.nextInt();
        b = scan.nextInt();
        c = scan.nextInt();
        d = scan.nextInt();

        if(a <= c){
            if(b > c){
                if(b <= d) {
                    ans = b - c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d > a){
                if(d <= b) {
                    ans = d - a;
                }else{
                    ans = b - a;
                }
            }
        }

        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a, b, c, d, ans = 0;
        a = scan.nextInt();
        b = scan.nextInt();
        c = scan.nextInt();
        d = scan.nextInt();

        if(a <= c){
            if(b > c){
                if(b <= d) {
                    ans = b - c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d > a){
                if(d <= b) {
                    ans = d - a;
                }else{
                    ans = b - a;
                }
            }
        }

        System.out.println(ans);
    } main {
        Scanner scan = new Scanner(System.in);

        int a, b, c, d, ans = 0;
        a = scan.nextInt();
        b = scan.nextInt();
        c = scan.nextInt();
        d = scan.nextInt();

        if(a <= c){
            if(b > c){
                if(b <= d) {
                    ans = b - c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d > a){
                if(d <= b) {
                    ans = d - a;
                }else{
                    ans = b - a;
                }
            }
        }

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

        int a, b, c, d, ans = 0;
        a = scan.nextInt();
        b = scan.nextInt();
        c = scan.nextInt();
        d = scan.nextInt();

        if(a <= c){
            if(b > c){
                if(b <= d) {
                    ans = b - c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d > a){
                if(d <= b) {
                    ans = d - a;
                }else{
                    ans = b - a;
                }
            }
        }

        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a, b, c, d, ans = 0;
        a = scan.nextInt();
        b = scan.nextInt();
        c = scan.nextInt();
        d = scan.nextInt();

        if(a <= c){
            if(b > c){
                if(b <= d) {
                    ans = b - c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d > a){
                if(d <= b) {
                    ans = d - a;
                }else{
                    ans = b - a;
                }
            }
        }

        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a, b, c, d, ans = 0;
        a = scan.nextInt();
        b = scan.nextInt();
        c = scan.nextInt();
        d = scan.nextInt();

        if(a <= c){
            if(b > c){
                if(b <= d) {
                    ans = b - c;
                }else{
                    ans = d - c;
                }
            }
        }else{
            if(d > a){
                if(d <= b) {
                    ans = d - a;
                }else{
                    ans = b - a;
                }
            }
        }

        System.out.println(ans);
    }
}
