#include<bits/stdc++.h>
using namespace std;

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T> bool chmin(T &a,const T b){if(a>b){a=b; return true;}return false;}
template<typename T> bool chmax(T &a,const T b){if(a<b){a=b; return true;}return false;}



int main(){
    int N, M; cin >> N >> M;
    vi L(M), R(M);
    for(int i=0; i<M; i++){
        cin >> L[i] >> R[i];
    }

    int l=L[0], r=R[0];
    bool flag=0;
    for(int i=1; i<M; i++){
        if(max(l, L[i]) <= min(r, R[i])){
            l=max(l, L[i]);
            r=min(r, R[i]);
        }
        else flag=true;
    }
    if(flag) cout << 0 << endl;
    else cout << r-l+1 << endl;
    return 0;
}
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  int arr[N+1];
  for(int i=0;i<=N;++i) arr[i] = 0;
  int L, R;
  for(int i=0;i<M;++i) {
    cin>>L>>R;
    L--;
    arr[L]++;
    arr[R]--;
  }
  for(int i=1;i<=N;++i) arr[i] += arr[i-1];
  int ans = 0;
  for(int i=0;i<=N;++i) {
    if(arr[i]==M) ans++;
  }
  cout<<ans<<endl;
}

