import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();
            System.out.println(Math.max(0, Math.min(B, D) - Math.max(A, C)));
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();
            System.out.println(Math.max(0, Math.min(B, D) - Math.max(A, C)));
        }
    }
} Main public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();
            System.out.println(Math.max(0, Math.min(B, D) - Math.max(A, C)));
        }
    } main {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();
            System.out.println(Math.max(0, Math.min(B, D) - Math.max(A, C)));
        }
    } try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();
            System.out.println(Math.max(0, Math.min(B, D) - Math.max(A, C)));
        } {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();
            System.out.println(Math.max(0, Math.min(B, D) - Math.max(A, C)));
        } Scanner in = new Scanner(System.in) Scanner in = new Scanner(System.in) new Scanner(System.in) int A = in.nextInt(); A in.nextInt() in.nextInt in int B = in.nextInt(); B in.nextInt() in.nextInt in int C = in.nextInt(); C in.nextInt() in.nextInt in int D = in.nextInt(); D in.nextInt() in.nextInt in System.out.println(Math.max(0, Math.min(B, D) - Math.max(A, C))) System.out.println System.out System System.out Math.max(0, Math.min(B, D) - Math.max(A, C)) Math.max Math 0 Math.min(B, D) - Math.max(A, C) Math.min(B, D) Math.min Math B D Math.max(A, C) Math.max Math A C String[] args args public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();
            System.out.println(Math.max(0, Math.min(B, D) - Math.max(A, C)));
        }
    }
} public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();
            System.out.println(Math.max(0, Math.min(B, D) - Math.max(A, C)));
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();
            System.out.println(Math.max(0, Math.min(B, D) - Math.max(A, C)));
        }
    }
}
