import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();

        //Not merged case
        if (B <= C || D <= A) {
            System.out.print(0);
            return;
        }

        //One range is in the other range
        if (A <= C && D <= B) {
            System.out.print(D - C);
            return;
        }
        if (C <= A && B <= D) {
            System.out.print(B - A);
        }

        //Merged two range
        if (A < C && B < D) {
            System.out.print(B - C);
            return;
        }

        if (C < A && D < B){
            System.out.print(D - A);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();

        //Not merged case
        if (B <= C || D <= A) {
            System.out.print(0);
            return;
        }

        //One range is in the other range
        if (A <= C && D <= B) {
            System.out.print(D - C);
            return;
        }
        if (C <= A && B <= D) {
            System.out.print(B - A);
        }

        //Merged two range
        if (A < C && B < D) {
            System.out.print(B - C);
            return;
        }

        if (C < A && D < B){
            System.out.print(D - A);
        }
    }
} Main public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();

        //Not merged case
        if (B <= C || D <= A) {
            System.out.print(0);
            return;
        }

        //One range is in the other range
        if (A <= C && D <= B) {
            System.out.print(D - C);
            return;
        }
        if (C <= A && B <= D) {
            System.out.print(B - A);
        }

        //Merged two range
        if (A < C && B < D) {
            System.out.print(B - C);
            return;
        }

        if (C < A && D < B){
            System.out.print(D - A);
        }
    } main {

        Scanner scanner = new Scanner(System.in);

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();

        //Not merged case
        if (B <= C || D <= A) {
            System.out.print(0);
            return;
        }

        //One range is in the other range
        if (A <= C && D <= B) {
            System.out.print(D - C);
            return;
        }
        if (C <= A && B <= D) {
            System.out.print(B - A);
        }

        //Merged two range
        if (A < C && B < D) {
            System.out.print(B - C);
            return;
        }

        if (C < A && D < B){
            System.out.print(D - A);
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int A = scanner.nextInt(); A scanner.nextInt() scanner.nextInt scanner int B = scanner.nextInt(); B scanner.nextInt() scanner.nextInt scanner int C = scanner.nextInt(); C scanner.nextInt() scanner.nextInt scanner int D = scanner.nextInt(); D scanner.nextInt() scanner.nextInt scanner if (B <= C || D <= A) {
            System.out.print(0);
            return;
        } B <= C || D <= A B <= C B C D <= A D A {
            System.out.print(0);
            return;
        } System.out.print(0) System.out.print System.out System System.out 0 return; if (A <= C && D <= B) {
            System.out.print(D - C);
            return;
        } A <= C && D <= B A <= C A C D <= B D B {
            System.out.print(D - C);
            return;
        } System.out.print(D - C) System.out.print System.out System System.out D - C D C return; if (C <= A && B <= D) {
            System.out.print(B - A);
        } C <= A && B <= D C <= A C A B <= D B D {
            System.out.print(B - A);
        } System.out.print(B - A) System.out.print System.out System System.out B - A B A if (A < C && B < D) {
            System.out.print(B - C);
            return;
        } A < C && B < D A < C A C B < D B D {
            System.out.print(B - C);
            return;
        } System.out.print(B - C) System.out.print System.out System System.out B - C B C return; if (C < A && D < B){
            System.out.print(D - A);
        } C < A && D < B C < A C A D < B D B {
            System.out.print(D - A);
        } System.out.print(D - A) System.out.print System.out System System.out D - A D A String[] args args public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();

        //Not merged case
        if (B <= C || D <= A) {
            System.out.print(0);
            return;
        }

        //One range is in the other range
        if (A <= C && D <= B) {
            System.out.print(D - C);
            return;
        }
        if (C <= A && B <= D) {
            System.out.print(B - A);
        }

        //Merged two range
        if (A < C && B < D) {
            System.out.print(B - C);
            return;
        }

        if (C < A && D < B){
            System.out.print(D - A);
        }
    }
} public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();

        //Not merged case
        if (B <= C || D <= A) {
            System.out.print(0);
            return;
        }

        //One range is in the other range
        if (A <= C && D <= B) {
            System.out.print(D - C);
            return;
        }
        if (C <= A && B <= D) {
            System.out.print(B - A);
        }

        //Merged two range
        if (A < C && B < D) {
            System.out.print(B - C);
            return;
        }

        if (C < A && D < B){
            System.out.print(D - A);
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();

        //Not merged case
        if (B <= C || D <= A) {
            System.out.print(0);
            return;
        }

        //One range is in the other range
        if (A <= C && D <= B) {
            System.out.print(D - C);
            return;
        }
        if (C <= A && B <= D) {
            System.out.print(B - A);
        }

        //Merged two range
        if (A < C && B < D) {
            System.out.print(B - C);
            return;
        }

        if (C < A && D < B){
            System.out.print(D - A);
        }
    }
}