#include <bits/stdc++.h>
using namespace std;
inline int ReadInt() {
  static int n, ch;
  n = 0, ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
  return n;
}
const int maxn = 100000 + 3;
int val[maxn];
int n, m;
int main() {
  n = ReadInt(), m = ReadInt();
  val[0] = 1;
  for (int i = 0; i < m; ++i) {
    int f = ReadInt() - 1, t = ReadInt() - 1;
    if (f > t) swap(f, t);
    val[0]--, val[f]++, val[t]--;
  }
  int now = 0, ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    now += val[i];
    ans += max(now, 0);
  }
  printf("%d\n", max(ans, 0));
  return 0;
}
