#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define reep(i,n) for(ll i = n; i >-1; i--)
#define deb(variable) cout<<#variable<<"="<<variable<<endl
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999999;
const ll MOD=128;
const ll MAX_N=500010;
ll a,b,c,d,e,x,y,z,k,m,n,l,q,ans=0;
vl v,v1;
vp p[100010];
string s;
ll solve(void){
    if(v.back()>v1[0])return 0;
    return v1[0]-v.back()+1;
}
int main(){
    cin>>n>>m;
    rep(i,m){
     cin>>a>>b;
     v.push_back(a);
     v1.push_back(b);
    }
 
    sort(v.begin(),v.end());
    sort(v1.begin(),v1.end());
 
    cout<<solve()<<endl;
}