#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
typedef long long ll;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int main() {
    int n, m; cin >> n >> m;
    int table[100002] = {0};
    rep(i, m) {
        int l, r; cin >> l >> r;
        table[l]++;
        table[r + 1]--;
    }
    rrep(i, 1, 100002) table[i] += table[i - 1];
    int c = 0;
    rep(i, 100002) if (table[i] == m) c++;
    cout << c << endl;
}
