#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,M;
  cin>>N>>M;
  vector<long long> l(M);
  vector<long long> r(M);
  for(long long i=0;i<M;i++)
    cin>>l.at(i)>>r.at(i);
  sort(l.begin(),l.end());
  sort(r.begin(),r.end());
  long long a=r.at(0)-l.at(M-1)+1;
  if(a>0)
  cout<<a<<endl;
  else
    cout<<0<<endl;
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; i++)

int main() {
  int n,m; cin >> n >> m;
  int l,u; l = 0; u = (int)1e6;
  rep(i, m){
    int p, q; cin >> p >> q;
    if(l < p) l = p;
    if(q < u) u = q;
  }
  
  cout << max(u - l + 1, 0) << endl;
}