#include <bits/stdc++.h>
using namespace std;
vector<int> L(10010);
vector<int> R(10010);
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> L[i];
    cin >> R[i];
  }
  int maxL, minR;
  maxL = L[0];
  minR = R[0];
  for (int i = 0; i < M; i++) {
    if (L[i] > maxL) maxL = L[i];
    if (R[i] < minR) minR = R[i];
  }
  int ans = 0;
  if (maxL > minR) {
    ans = 0;
  } else {
    for (int i = maxL; i <= minR; i++) ans++;
  }
  cout << ans << endl;
}
