#include<iostream>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  int mm[100010] = {};  
  for(int i = 0; i < m; ++i){
    int x,y;cin>>x>>y;
    mm[x]++;
    mm[y+1]--;
  }
  int ans = 0;
  for(int i = 1; i< n+1; ++ i){
    mm[i]+=mm[i-1];
    if(mm[i] >= m)ans++;
  }
  cout<<ans<<endl;
  
}
