import java.util.Scanner;

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

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        if (c >= b || a >= d)
            System.out.println(0);
        else if ((a <= c && b >= d) || (c <= a && d >= b))
            System.out.println((b - a) < (d - c) ? b - a : d - c);
        else
            System.out.println((b > c && c >= a) ? b - c : d - a);

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

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        if (c >= b || a >= d)
            System.out.println(0);
        else if ((a <= c && b >= d) || (c <= a && d >= b))
            System.out.println((b - a) < (d - c) ? b - a : d - c);
        else
            System.out.println((b > c && c >= a) ? b - c : d - a);

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

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        if (c >= b || a >= d)
            System.out.println(0);
        else if ((a <= c && b >= d) || (c <= a && d >= b))
            System.out.println((b - a) < (d - c) ? b - a : d - c);
        else
            System.out.println((b > c && c >= a) ? b - c : d - a);

    } main {
        Scanner stdIn = new Scanner(System.in);

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        if (c >= b || a >= d)
            System.out.println(0);
        else if ((a <= c && b >= d) || (c <= a && d >= b))
            System.out.println((b - a) < (d - c) ? b - a : d - c);
        else
            System.out.println((b > c && c >= a) ? b - c : d - a);

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

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        if (c >= b || a >= d)
            System.out.println(0);
        else if ((a <= c && b >= d) || (c <= a && d >= b))
            System.out.println((b - a) < (d - c) ? b - a : d - c);
        else
            System.out.println((b > c && c >= a) ? b - c : d - a);

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

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        if (c >= b || a >= d)
            System.out.println(0);
        else if ((a <= c && b >= d) || (c <= a && d >= b))
            System.out.println((b - a) < (d - c) ? b - a : d - c);
        else
            System.out.println((b > c && c >= a) ? b - c : d - a);

    }
} Main
import java.util.Scanner;

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

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();

        if (c >= b || a >= d)
            System.out.println(0);
        else if ((a <= c && b >= d) || (c <= a && d >= b))
            System.out.println((b - a) < (d - c) ? b - a : d - c);
        else
            System.out.println((b > c && c >= a) ? b - c : d - a);

    }
}
