#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long int INF = 9e18 + 2e17;
const int inf = 2e9;
const int N = 5000 + 22;
const double eps = 1e-10;
const double PI = 3.14159265;
int n, m;
int cnt[3][N];
int a[N];
pair<int, int> f[N];
void _solve() {
  cin >> n >> m;
  for (int i = (int)0; i < (int)m; i++) {
    cin >> f[i].first >> f[i].second;
    a[f[i].first]++, a[f[i].second + 1]--;
  }
  sort(f, f + m);
  for (int i = (int)1; i <= (int)n; i++) a[i] += a[i - 1];
  for (int i = (int)0; i < (int)3; i++)
    for (int j = (int)1; j <= (int)n; j++) {
      cnt[i][j] = cnt[i][j - 1];
      if (a[j] == i) cnt[i][j]++;
    }
  int ans = 0;
  for (int i = (int)0; i < (int)m; i++) {
    for (int j = (int)i + 1; j < (int)m; j++) {
      int sum = cnt[0][n];
      if (f[i].second >= f[j].first) {
        sum += cnt[2][min(f[i].second, f[j].second)] - cnt[2][f[j].first - 1];
        sum += cnt[1][f[j].first - 1] - cnt[1][f[i].first - 1];
        sum += abs(cnt[1][f[j].second] - cnt[1][f[i].second]);
      } else {
        sum += cnt[1][f[i].second] - cnt[1][f[i].first - 1];
        sum += cnt[1][f[j].second] - cnt[1][f[j].first - 1];
      }
      ans = max(ans, n - sum);
    }
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  _solve();
  return 0;
}
