#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<ll> sum(100010, 0);
    for(int i = 0; i < m; i++)
    {
        int l, r; cin >> l >> r;
        sum[l]++;
        sum[r + 1]--;
    }
    ll max_v = 0;
    for(int i = 1; i < sum.size(); i++)
    {
        sum[i] += sum[i - 1];
    }
    ll ans = 0;
    for(int i = 1; i < sum.size(); i++)
    {
        if(m == sum[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}
