#include <bits/stdc++.h>
using namespace std;
const int maxn = 5050;
int a[maxn];
struct node {
  int l, r;
};
node fuck[maxn];
int have[maxn], tmp[maxn], prefix[maxn];
int main() {
  int i, j, k, n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    memset(have, 0, sizeof(have));
    for (i = 1; i <= m; i++) {
      scanf("%d%d", &fuck[i].l, &fuck[i].r);
      for (j = fuck[i].l; j <= fuck[i].r; j++) have[j]++;
    }
    prefix[0] = 0;
    int ans = 0;
    for (i = 1; i <= m; i++) {
      for (j = 1; j <= n; j++) tmp[j] = have[j];
      for (j = fuck[i].l; j <= fuck[i].r; j++) tmp[j]--;
      int res = 0;
      for (j = 1; j <= n; j++)
        if (tmp[j] == 0) res++;
      for (j = 1; j <= n; j++)
        if (tmp[j] == 1)
          prefix[j] = 1;
        else
          prefix[j] = 0;
      for (j = 1; j <= n; j++) prefix[j] += prefix[j - 1];
      int minmove = n + 1;
      for (j = 1; j <= m; j++)
        if (i != j) {
          minmove = min(minmove, prefix[fuck[j].r] - prefix[fuck[j].l - 1]);
        }
      res += minmove;
      ans = max(ans, n - res);
    }
    printf("%d\n", ans);
  }
}
