import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    long a, b, c, d;
    scan(a, b, c, d);
    auto tmp = new long[](100000);
    foreach (i; a .. b)
    {
        tmp[i] += 1;
    }
    foreach (i; c .. d)
    {
        tmp[i] += 1;
    }
    // writeln(tmp);
    long cnt;
    foreach (i; 0 .. tmp.length)
    {
        if (tmp[i] == 2)
        {
            cnt += 1;
        }
    }
    writeln(cnt);
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}
