import java.util.*;

public class Main {

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int start = Math.max(A, C);
        int end = Math.min(B, D);
        int reult = end - start;
        System.out.println(reult < 0 ? 0 : reult);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int start = Math.max(A, C);
        int end = Math.min(B, D);
        int reult = end - start;
        System.out.println(reult < 0 ? 0 : reult);
    } main {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int start = Math.max(A, C);
        int end = Math.min(B, D);
        int reult = end - start;
        System.out.println(reult < 0 ? 0 : reult);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int A = sc.nextInt(); A sc.nextInt() sc.nextInt sc int B = sc.nextInt(); B sc.nextInt() sc.nextInt sc int C = sc.nextInt(); C sc.nextInt() sc.nextInt sc int D = sc.nextInt(); D sc.nextInt() sc.nextInt sc 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 int reult = end - start; reult end - start end start System.out.println(reult < 0 ? 0 : reult) System.out.println System.out System System.out reult < 0 ? 0 : reult reult < 0 reult 0 0 reult String[] args args public class Main {

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int start = Math.max(A, C);
        int end = Math.min(B, D);
        int reult = end - start;
        System.out.println(reult < 0 ? 0 : reult);
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int start = Math.max(A, C);
        int end = Math.min(B, D);
        int reult = end - start;
        System.out.println(reult < 0 ? 0 : reult);
    }
}
