void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], m = tmp[1];
    int[] a = new int[n+1];
    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) {
        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;