import std.algorithm;
import std.range;
import std.stdio;
import std.math;
import std.array;
import std.string;
import std.conv;
import std.typecons;

/// 数列の読み込み
auto readNums() {
	return readln().chomp.split.map!(to!int).array;
}

/// 数の読み込み
auto readNum() {
	return readNums.front;
}

/// 指定行数読み込み
auto readRows(size_t rows) {
	return generate(() => readln().chomp).take(rows).array;
}

auto range(int a, int b, int c, int d) {
    if(a <= c && c <= b) {
        return (a <= d && d <= b) ? tuple(c, d) : tuple(c, b);
    } else if(c <= a && a <= d) {
        return (c <= b && b <= d) ? tuple(a, b) : tuple(a, d);
    }
    return tuple(0, 0);
}

void main() {
    const nums = readNums();
    immutable r = range(nums[0], nums[1], nums[2], nums[3]);
    writefln("%d", r[1] - r[0]);
}