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

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() {
    auto xs = readints();
    int a = xs[0], b = xs[1], c = xs[2], d = xs[3];

    int start = max(a, c);
    int end = min(b, d);
    writeln(max(0, end - start));
}
