#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long inf = numeric_limits<long long>::max() / 2;
const long double eps = 1e-9;
const long double pi = acosl(-1);
template <typename T>
inline bool mineq(T& a, T b) {
  return (a > b) ? (a = b, 1) : 0;
}
template <typename T>
inline bool maxeq(T& a, T b) {
  return (a < b) ? (a = b, 1) : 0;
}
void solve(), read();
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  read();
  solve();
  return 0;
}
const long long MAXN = 5001;
long long n, q;
vector<pair<long long, long long> > a;
vector<long long> c;
vector<long long> vs[MAXN];
long long un1[MAXN];
long long un2[MAXN][MAXN];
void solve() {
  for (long long i = 0; i < q; i++) {
    for (long long z = a[i].first; z <= a[i].second; z++) {
      if ((long long)((vs[z]).size()) < 3) {
        vs[z].push_back(i);
      }
    }
  }
  long long cnt = 0;
  for (long long i = 0; i < n; i++) {
    if ((long long)((vs[i]).size()) == 1) {
      ++un1[vs[i][0]];
    }
    if ((long long)((vs[i]).size()) == 2) {
      ++un2[vs[i][0]][vs[i][1]];
      ++un2[vs[i][1]][vs[i][0]];
    }
    if ((long long)((vs[i]).size())) {
      ++cnt;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < q; i++) {
    for (long long j = 0; j < q; j++) {
      if (i == j) continue;
      maxeq(ans, cnt - un1[i] - un1[j] - un2[i][j]);
    }
  }
  cout << ans << "\n";
}
void read() {
  cin >> n >> q;
  for (long long i = 0; i < q; i++) {
    long long l, r;
    cin >> l >> r;
    --l, --r;
    a.push_back({l, r});
  }
}
