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

int overlap(int a, int b, int c, int d) {
    int lo = max(a, c);
    int hi = min(b, d);
    return max(0, hi - lo);
}

void main() {
    int a, b, c, d; scan(a, b, c, d);
    writeln(overlap(a, b, c, d));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
