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 n, m;
    scan(n, m);
    long max_x = long.min;
    long min_x = long.max;
    foreach (_; 0 .. m)
    {
        long l, r;
        scan(l, r);
        // writeln(l, r);
        max_x = max(max_x, l);
        min_x = min(min_x, r);

    }
    // writeln("max", max_x);
    // writeln("min", min_x);
    if (min_x >= max_x)
    {
        writeln(min_x - max_x + 1);

    }
    else
    {
        writeln(0);
    }

}

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;
}
