#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> c(n+2);
    rep(i,m){
        int l, r;
        cin >> l >> r;
        c[l]++;
        c[r+1]--;
    }
    rep(i,n+1) c[i+1] += c[i];
    int ans = 0;
    rep(i,n+1) if(c[i] == m) ans++;
    cout << ans << endl;
}
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


int main(){
    int N, M;
    cin >> N >> M;

    int low = 0;
    int high = N;
    rep(i,M){
        int a, b;
        cin >> a >> b;

        if(low<a)low = a;
        if(b<high)high = b;
    }

    if(high-low<0)cout << 0 << endl;
    else cout << high-low+1<< endl;
}

