#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long int n, k, m, res = 0, ans = 0, sm = 0, edge = -1, A, B;
int base1 = 31;
long long int mod1 = 1e9 + 9;
int base2 = 59;
long long int mod2 = 1e9 + 7;
long long int a[500005] = {0};
set<pair<int, int> > st, st1, st2;
set<long long int> stres;
string s, s1, s2, s3, s4;
vector<long long int> v, vnode, vans, v3;
vector<pair<int, int> > vv, vv1, adj, v1, v2;
vector<pair<int, pair<int, int> > > vvv;
priority_queue<long long int> q;
map<pair<long long int, long long int>, long long int> mp;
set<pair<int, int> >::iterator it, it1, it2;
int voyel(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y')
    return 1;
  return 0;
}
int dp1[5001][5001], dp2[5001][5001];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long int i = 0, j = 0, x, y, z = 0, mx = 0, nb0 = 0, nb = 0, nbmax = 0,
                nbinf = 0, mm = 5e9, idx = 0, ok = 0, l, r, negatif = 0,
                positif = 0, q, d;
  char c;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> l >> r;
    for (j = l; j <= r; j++) a[j]++;
    vv.push_back({l, r});
  }
  memset(dp1, 0, sizeof(dp1));
  memset(dp2, 0, sizeof(dp2));
  for (i = 1; i <= n; i++) {
    long long int cnt1 = 0, cnt2 = 0;
    for (j = i; j <= n; j++) {
      if (a[j] == 1) {
        cnt1++;
      }
      if (a[j] == 2 || a[j] == 1) cnt2++;
      dp1[i][j] = cnt1;
      dp2[i][j] = cnt2;
    }
  }
  nb = 0;
  for (i = 1; i <= n; i++)
    if (a[i] != 0) nb++;
  res = 0;
  ans = 0;
  for (i = 0; i < m; i++) {
    for (j = 0; j < m; j++) {
      if (j == i) continue;
      ans = 0;
      long long int l1 = vv[i].first, r1 = vv[i].second;
      long long int l2 = vv[j].first, r2 = vv[j].second;
      long long int lmid = max(l1, l2);
      long long int rmid = min(r1, r2);
      r2 = max(r1, r2);
      if (lmid <= rmid) {
        l1 = min(l1, l2);
        r1 = lmid - 1;
        l2 = rmid + 1;
        ans = dp1[l1][r1] + dp2[lmid][rmid] + dp1[l2][r2];
        res = max(res, nb - ans);
      } else {
        ans = dp1[l1][r1] + dp1[l2][r2];
        res = max(res, nb - ans);
      }
    }
  }
  res = max(res, 0LL);
  cout << res;
  return 0;
}
