#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> L, R;
int main() {
  scanf("%d %d", &N, &M);
  L.resize(M);
  R.resize(M);
  for (int i = 0; i < M; i++) {
    int left, right;
    scanf("%d %d", &left, &right);
    L[i] = left - 1;
    R[i] = right - 1;
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    bool flag = 1;
    for (int j = 0; j < M; j++)
      if (i < L[j] || R[j] < i) flag = 0;
    if (flag) count++;
  }
  printf("%d\n", count);
  return 0;
}
