const main = input => 
    ((m, a, b, c, d) => m.find(x => x[0](a, b, c, d))[1](a, b, c, d))(
        [
            [
                // 1. a <= b <= c <= d
                (a, b, c, d) => b <= c,
                (a, b, c, d) => 0,
            ],
            [
                // 2. a <= c <= b <= d
                (a, b, c, d) => a <= c && c <= b && b <= d,
                (a, b, c, d) => b - c,
            ],
            [
                // 3. a <= c <= d <= b
                (a, b, c, d) => a <= c && d <= b,
                (a, b, c, d) => d - c,
            ],
            [
                // 4. c <= a <= d <= b
                (a, b, c, d) => c <= a && a <= d && d <= b,
                (a, b, c, d) => d - a,
            ],
            [
                // 5. c <= a <= b <= d
                (a, b, c, d) => c <= a && b <= d,
                (a, b, c, d) => b - a,
            ],
            [
                // 6. c <= d <= a <= b
                (a, b, c, d) => d <= a,
                (a, b, c, d) => 0,
            ],
        ],
        ...input.trim().split(' ').map(x => +x)
    );

console.log(main(require('fs').readFileSync('/dev/stdin', 'utf8')));
