#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 577;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100505;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a - b) < 1e-9; }
inline bool IF(int a, int b, int c) { return (a >= b && a <= c); }
inline bool IFS(int a, int b, int c) { return (a > b && a < c); }
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) {
    _in >> _i;
  }
  return _in;
}
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
pii a[5005];
int p[5005];
int ed[5005], dw[5005];
int inline solve() {
  ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
  ;
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < q; ++i) {
    cin >> a[i].first >> a[i].second;
    p[a[i].first]++;
    p[a[i].second + 1]--;
  }
  int val = 0;
  for (int i = 1; i <= n + 2; ++i) {
    p[i] += p[i - 1];
    if (p[i] != 0) val++;
    if (p[i] == 1) ed[i]++;
    ed[i] += ed[i - 1];
    if (p[i] == 2) dw[i]++;
    dw[i] += dw[i - 1];
  }
  int ans = 0;
  for (int i = 0; i < q; ++i) {
    for (int j = 0; j < q; ++j) {
      if (i == j) continue;
      int res = 0;
      if (a[i].first <= a[j].first && a[j].second <= a[i].second) {
        res += ed[a[j].first - 1] - ed[a[i].first - 1];
        res += ed[a[i].second] - ed[a[j].second];
        res += dw[a[j].second] - dw[a[j].first - 1];
      } else if (a[j].first <= a[i].first && a[i].second <= a[j].second) {
        res += ed[a[i].first - 1] - ed[a[j].first - 1];
        res += ed[a[j].second] - ed[a[i].second];
        res += dw[a[i].second] - dw[a[i].first - 1];
      } else if (a[i].first <= a[j].first && a[j].first <= a[i].second) {
        res += ed[a[j].first - 1] - ed[a[i].first - 1];
        res += ed[a[j].second] - ed[a[i].second];
        res += dw[a[i].second] - dw[a[j].first - 1];
      } else if (a[j].first <= a[i].first && a[i].first <= a[j].second) {
        res += ed[a[i].first - 1] - ed[a[j].first - 1];
        res += ed[a[i].second] - ed[a[j].second];
        res += dw[a[j].second] - dw[a[i].first - 1];
      } else {
        res += ed[a[i].second] - ed[a[i].first - 1];
        res += ed[a[j].second] - ed[a[j].first - 1];
      }
      ans = max(ans, val - res);
    }
  }
  cout << ans;
  return 0;
}
int32_t main() {
  solve();
  return 0;
}
