#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
const long long inf = 0x3f3f3f3f3f;
long long a[maxn];
long long n, q;
long long l[maxn], r[maxn];
long long one[maxn], two[maxn];
int main() {
  cin >> n >> q;
  for (int i = 1; i <= q; i++) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++) a[j]++;
  }
  long long tot = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i]) tot++;
    if (a[i] == 1) one[i]++;
    if (a[i] == 2) two[i]++;
    one[i] += one[i - 1];
    two[i] += two[i - 1];
  }
  long long ans = 0;
  for (int i = 1; i <= q; i++) {
    for (int j = i + 1; j <= q; j++) {
      long long lf = max(l[i], l[j]);
      long long rt = min(r[i], r[j]);
      long long tmp = one[r[i]] - one[l[i] - 1] + one[r[j]] - one[l[j] - 1];
      if (lf <= rt) {
        tmp -= one[rt] - one[lf - 1];
        tmp += two[rt] - two[lf - 1];
      }
      ans = max(ans, tot - tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
