import java.util.*;

public class Main {
//    private static final String ex = "0 75 25 100";
    private static final String ex = "10 90 20 80";

    public static void main(String[] args) {
        System.out.println(solve(new Scanner(System.in)));
//        System.out.println(solve(new Scanner(ex)));
    }

    private static int solve(Scanner scanner) {
        String[] split = scanner.nextLine().split(" ");

        int A = Integer.parseInt(split[0]);
        int B = Integer.parseInt(split[1]);
        int C = Integer.parseInt(split[2]);
        int D = Integer.parseInt(split[3]);

        if (B <= C || D <= A) return 0;
        else if (C <= A && B <= D) return B - A;
        else if (A <= C && D <= B) return D - C;
        else if (A <= C) return B - C;
        else if (C <= A) return D - A;
        else throw new RuntimeException();
    }
}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz