import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    int hi = N;
    int lo = 1;
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        lo = max(lo, s[0]);
        hi = min(hi, s[1]);
    }
    if (lo > hi) {
        writeln(0);
    } else {
        writeln(hi - lo + 1);
    }
}
