#include <bits/stdc++.h>
using namespace std;
int main () {
int a[10010] = {0}, l, m, u, v, as = 0;
cin >> l >> m;
for (int x = 0; x <= 10000; x++) {
a[x] = 1;
}
while (cin >> u >> v) {
for (int y = v; y >= u; y--) {
a[y] = 0;
}
}
for (int z = 0; z <= 10000; z++) {
as = as + a[z];
}
cout << as;
}