void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], m = tmp[1];
    long[] a = new long[n+2];
    foreach (i; 0 .. m) {
        tmp = readln.split.to!(int[]);
        int l = tmp[0] - 1, r = tmp[1];
        ++a[l];
        --a[r];
    }
    foreach (i; 0 .. n+1) {
        a[i+1] += a[i];
    }
    a.count(m).writeln;
}

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