#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
inline int read() {
  int s = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
  return s;
}
const int N = 5005;
int n, q;
int l[N], r[N], a[N], b[N];
int main() {
  n = read(), q = read();
  for (int i = 1; i <= q; i++) {
    l[i] = read(), r[i] = read();
    for (int j = l[i]; j <= r[i]; j++) a[j]++;
  }
  int sum = 0;
  for (int i = 1; i <= q; i++) {
    int cnt = 0, num = 0, ans = 5000;
    for (int j = l[i]; j <= r[i]; j++) a[j]--;
    for (int j = 1; j <= n; j++) {
      if (a[j] == 1)
        b[j] = 1;
      else
        b[j] = 0;
      if (a[j] == 0) num++;
    }
    for (int j = n; j >= 1; j--) b[j] += b[j + 1];
    for (int j = 1; j <= q; j++) {
      if (j == i) continue;
      ans = ((ans) < (b[l[j]] - b[r[j] + 1]) ? (ans) : (b[l[j]] - b[r[j] + 1]));
    }
    sum = ((sum) > (n - num - ans) ? (sum) : (n - num - ans));
    for (int j = l[i]; j <= r[i]; j++) a[j]++;
  }
  printf("%d", sum);
  return 0;
}
