#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,i,t;
  cin>>n>>m;
  t=m-1;
  int mn,mx,l,r;
  cin>>l>>r;
  mn=r;
  mx=l;
  while(t--)
  {
    cin>>l>>r;
    mx=max(mx,l);
    mn=min(mn,r);
  }
  if(mn>=mx) cout<<(mn-mx)+1;
  else cout<<0;
  return 0; 
}