import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // write your code here
        //dream dreamer erase eraser
        int A;
        int B;
        int C;
        int D;
        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            D = sc.nextInt();

        }
        if (B < C || D < A) {
            System.out.println("0");
        } else {
            int start = Math.max(A, C);
            int end = Math.min(B, D);
            System.out.println(end - start);
        }

    }

} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        // write your code here
        //dream dreamer erase eraser
        int A;
        int B;
        int C;
        int D;
        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            D = sc.nextInt();

        }
        if (B < C || D < A) {
            System.out.println("0");
        } else {
            int start = Math.max(A, C);
            int end = Math.min(B, D);
            System.out.println(end - start);
        }

    }

} Main public static void main(String[] args) {
        // write your code here
        //dream dreamer erase eraser
        int A;
        int B;
        int C;
        int D;
        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            D = sc.nextInt();

        }
        if (B < C || D < A) {
            System.out.println("0");
        } else {
            int start = Math.max(A, C);
            int end = Math.min(B, D);
            System.out.println(end - start);
        }

    } main {
        // write your code here
        //dream dreamer erase eraser
        int A;
        int B;
        int C;
        int D;
        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            D = sc.nextInt();

        }
        if (B < C || D < A) {
            System.out.println("0");
        } else {
            int start = Math.max(A, C);
            int end = Math.min(B, D);
            System.out.println(end - start);
        }

    } int A; A int B; B int C; C int D; D try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            D = sc.nextInt();

        } {
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            D = sc.nextInt();

        } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) A = sc.nextInt() A sc.nextInt() sc.nextInt sc B = sc.nextInt() B sc.nextInt() sc.nextInt sc C = sc.nextInt() C sc.nextInt() sc.nextInt sc D = sc.nextInt() D sc.nextInt() sc.nextInt sc if (B < C || D < A) {
            System.out.println("0");
        } else {
            int start = Math.max(A, C);
            int end = Math.min(B, D);
            System.out.println(end - start);
        } B < C || D < A B < C B C D < A D A {
            System.out.println("0");
        } System.out.println("0") System.out.println System.out System System.out "0" {
            int start = Math.max(A, C);
            int end = Math.min(B, D);
            System.out.println(end - start);
        } int start = Math.max(A, C); start Math.max(A, C) Math.max Math A C int end = Math.min(B, D); end Math.min(B, D) Math.min Math B D System.out.println(end - start) System.out.println System.out System System.out end - start end start String[] args args public class Main {
    public static void main(String[] args) {
        // write your code here
        //dream dreamer erase eraser
        int A;
        int B;
        int C;
        int D;
        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            D = sc.nextInt();

        }
        if (B < C || D < A) {
            System.out.println("0");
        } else {
            int start = Math.max(A, C);
            int end = Math.min(B, D);
            System.out.println(end - start);
        }

    }

} public class Main {
    public static void main(String[] args) {
        // write your code here
        //dream dreamer erase eraser
        int A;
        int B;
        int C;
        int D;
        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            D = sc.nextInt();

        }
        if (B < C || D < A) {
            System.out.println("0");
        } else {
            int start = Math.max(A, C);
            int end = Math.min(B, D);
            System.out.println(end - start);
        }

    }

} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // write your code here
        //dream dreamer erase eraser
        int A;
        int B;
        int C;
        int D;
        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            D = sc.nextInt();

        }
        if (B < C || D < A) {
            System.out.println("0");
        } else {
            int start = Math.max(A, C);
            int end = Math.min(B, D);
            System.out.println(end - start);
        }

    }

}
