import std.stdio, std.array, std.conv, std.typecons, std.algorithm;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

void main() {
    immutable ip = readln.split.to!(ulong[]);
    immutable n = ip[0], m = ip[1];

    auto ls = new ulong[m];
    auto rs = new ulong[m];

    for(ulong i = 0; i < m; i++) {
        immutable ip1 = readln.split.to!(ulong[]);
        immutable l = ip1[0], r = ip1[1];
        ls[i] = l;
        rs[i] = r;
    }

    ulong max_l = ls[0], min_r = rs[0];
    ulong invalid = false;
    for (ulong i = 1; i < m; i++) {
        if (ls[i] > max_l) max_l = ls[i];
        if (rs[i] < min_r) min_r = rs[i];
        if (max_l > min_r) {invalid = true; break;}
    }
    writeln(invalid ? 0 : min_r-max_l+1);
}
