import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String[] sl = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);
            int C = Integer.parseInt(sl[2]);
            int D = Integer.parseInt(sl[3]);

            int ans = 0;
            if (A <= C && C <= B) ans = Math.min(B, D) - C;
            else if (A <= D && D <= B) ans = D - Math.max(A, C);
            else if (C < A && B < D) ans = B - A;

            System.out.println(ans);
        }
    }
} import java.io.IOException; IOException java.io import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String[] sl = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);
            int C = Integer.parseInt(sl[2]);
            int D = Integer.parseInt(sl[3]);

            int ans = 0;
            if (A <= C && C <= B) ans = Math.min(B, D) - C;
            else if (A <= D && D <= B) ans = D - Math.max(A, C);
            else if (C < A && B < D) ans = B - A;

            System.out.println(ans);
        }
    }
} Main public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String[] sl = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);
            int C = Integer.parseInt(sl[2]);
            int D = Integer.parseInt(sl[3]);

            int ans = 0;
            if (A <= C && C <= B) ans = Math.min(B, D) - C;
            else if (A <= D && D <= B) ans = D - Math.max(A, C);
            else if (C < A && B < D) ans = B - A;

            System.out.println(ans);
        }
    } main {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String[] sl = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);
            int C = Integer.parseInt(sl[2]);
            int D = Integer.parseInt(sl[3]);

            int ans = 0;
            if (A <= C && C <= B) ans = Math.min(B, D) - C;
            else if (A <= D && D <= B) ans = D - Math.max(A, C);
            else if (C < A && B < D) ans = B - A;

            System.out.println(ans);
        }
    } try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String[] sl = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);
            int C = Integer.parseInt(sl[2]);
            int D = Integer.parseInt(sl[3]);

            int ans = 0;
            if (A <= C && C <= B) ans = Math.min(B, D) - C;
            else if (A <= D && D <= B) ans = D - Math.max(A, C);
            else if (C < A && B < D) ans = B - A;

            System.out.println(ans);
        } {
            final String s = reader.readLine();

            final String[] sl = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);
            int C = Integer.parseInt(sl[2]);
            int D = Integer.parseInt(sl[3]);

            int ans = 0;
            if (A <= C && C <= B) ans = Math.min(B, D) - C;
            else if (A <= D && D <= B) ans = D - Math.max(A, C);
            else if (C < A && B < D) ans = B - A;

            System.out.println(ans);
        } BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in)) BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in)) new BufferedReader(
                new InputStreamReader(System.in)) final String s = reader.readLine(); s reader.readLine() reader.readLine reader final String[] sl = s.split(" "); sl s.split(" ") s.split s " " int A = Integer.parseInt(sl[0]); A Integer.parseInt(sl[0]) Integer.parseInt Integer sl[0] sl 0 int B = Integer.parseInt(sl[1]); B Integer.parseInt(sl[1]) Integer.parseInt Integer sl[1] sl 1 int C = Integer.parseInt(sl[2]); C Integer.parseInt(sl[2]) Integer.parseInt Integer sl[2] sl 2 int D = Integer.parseInt(sl[3]); D Integer.parseInt(sl[3]) Integer.parseInt Integer sl[3] sl 3 int ans = 0; ans 0 if (A <= C && C <= B) ans = Math.min(B, D) - C;
            else if (A <= D && D <= B) ans = D - Math.max(A, C);
            else if (C < A && B < D) ans = B - A; A <= C && C <= B A <= C A C C <= B C B ans = Math.min(B, D) - C ans Math.min(B, D) - C Math.min(B, D) Math.min Math B D C if (A <= D && D <= B) ans = D - Math.max(A, C);
            else if (C < A && B < D) ans = B - A; A <= D && D <= B A <= D A D D <= B D B ans = D - Math.max(A, C) ans D - Math.max(A, C) D Math.max(A, C) Math.max Math A C if (C < A && B < D) ans = B - A; C < A && B < D C < A C A B < D B D 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) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String[] sl = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);
            int C = Integer.parseInt(sl[2]);
            int D = Integer.parseInt(sl[3]);

            int ans = 0;
            if (A <= C && C <= B) ans = Math.min(B, D) - C;
            else if (A <= D && D <= B) ans = D - Math.max(A, C);
            else if (C < A && B < D) ans = B - A;

            System.out.println(ans);
        }
    }
} public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String[] sl = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);
            int C = Integer.parseInt(sl[2]);
            int D = Integer.parseInt(sl[3]);

            int ans = 0;
            if (A <= C && C <= B) ans = Math.min(B, D) - C;
            else if (A <= D && D <= B) ans = D - Math.max(A, C);
            else if (C < A && B < D) ans = B - A;

            System.out.println(ans);
        }
    }
} Main
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String[] sl = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);
            int C = Integer.parseInt(sl[2]);
            int D = Integer.parseInt(sl[3]);

            int ans = 0;
            if (A <= C && C <= B) ans = Math.min(B, D) - C;
            else if (A <= D && D <= B) ans = D - Math.max(A, C);
            else if (C < A && B < D) ans = B - A;

            System.out.println(ans);
        }
    }
}
