#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  int L = 0, R = n + 1;
  for(int i = 0; i < m; i++) {
    int l,r;
    cin >> l >> r;
    L = max(l,L);
    R = min(r,R);
  }
  cout << max(R - L + 1,0) << endl;
}
