import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n, m; scan(n, m);
    auto a = new int[n + 2];
    for (int i = 0; i < m; i++) {
        int l, r; scan(l, r);
        a[l]++;
        a[r + 1]--;
    }

    for (int i = 1; i < a.length; i++) {
        a[i] += a[i - 1];
    }

    auto ans = a.count!(e => e == m);
    writeln(ans);
}
