#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
  cin>>n>>m;
  int l[m], r[m];
  for(int i=0; i<m; i++){
    cin>>l[i]>>r[i];
  }
  int k=*max_element(l, l+m);
  int q= *min_element(r, r+m);
  cout<<max(0,q-k+1);
}
