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

void main() {
    long n, m;
    readf("%d %d\n", &n, &m);
    auto xs = new long[](n+1);

    foreach (_; 0..m) {
        long l, r;
        readf("%d %d\n", &l, &r);
        xs[l-1] += 1;
        xs[r] -= 1;
    }

    auto ans = 0;
    auto cur = 0;
    foreach (x; xs) {
        cur += x;
        if (cur == m) {
            ans++;
        }
    }
    writeln(ans);
}
