#include <bits/stdc++.h>
using namespace std;
long long o[5005];
long long t[5005];
long long a[5005], n, b[5005], l[5005];
int main() {
  long long q, ans = 0, second = 0;
  cin >> n >> q;
  for (long long i = 0; i < q; i++) {
    cin >> a[i] >> b[i];
    l[a[i]]++;
    l[b[i] + 1]--;
  }
  for (long long i = 1; i <= 5004; i++) {
    l[i] += l[i - 1];
  }
  for (long long i = 1; i <= 5004; i++)
    if (l[i]) second++;
  for (long long i = 1; i <= 5004; i++) {
    if (l[i] == 1) {
      o[i]++;
    }
    if (l[i] == 2) {
      t[i]++;
    }
    o[i] = o[i] + o[i - 1];
    t[i] = t[i] + t[i - 1];
  }
  for (long long i = 0; i < q; i++) {
    for (long long j = i + 1; j < q; j++) {
      long long c = second;
      c = c - (o[b[i]] - o[a[i] - 1]);
      c = c - (o[b[j]] - o[a[j] - 1]);
      long long a1 = max(a[i], a[j]);
      long long b1 = min(b[i], b[j]);
      if (a1 <= b1) c = c - (t[b1] - t[a1 - 1]);
      ans = max(ans, c);
    }
  }
  cout << ans;
  return 0;
}
