#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:667177216")
using namespace std;
const long long MOD = 1000000000 + 7;
const long long MAXN = 3 * 100000 + 100;
string s;
int D[501][501][26];
int rec(int l, int r, char c) {
  if (l == r) {
    return s[l] == c ? 0 : 1;
  }
  if (D[l][r][c - 'a'] != -1) {
    return D[l][r][c - 'a'];
  }
  int result = min(rec(l + 1, r, s[l]) + (int)c != s[l],
                   rec(l, r - 1, s[r]) + (int)c != s[r]);
  return D[l][r][c - 'a'] = result;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> d(n + 2);
  vector<pair<int, int>> a(q);
  for (int(i) = 0; (i) < q; (i)++) {
    cin >> a[i].first >> a[i].second;
  }
  int zeros = 0;
  vector<int> pref_one(n + 2), pref_two(n + 2);
  for (int i = 0; i < q; ++i) {
    d[a[i].first]++;
    d[a[i].second + 1]--;
  }
  int cur = 0;
  for (int i = 1; i < n + 1; ++i) {
    pref_one[i] = pref_one[i - 1];
    pref_two[i] = pref_two[i - 1];
    cur += d[i];
    pref_one[i] += cur == 1;
    pref_two[i] += cur == 2;
    zeros += cur == 0;
  }
  sort((a).begin(), (a).end());
  int ans = 0;
  for (int i = 0; i < q; ++i) {
    for (int j = i + 1; j < q; ++j) {
      int tmp = zeros;
      tmp += pref_one[a[i].second] - pref_one[a[i].first - 1];
      tmp += pref_one[a[j].second] - pref_one[a[j].first - 1];
      int l = a[j].first;
      int r = min(a[j].second, a[i].second);
      if (l <= r) {
        tmp += pref_two[r] - pref_two[l - 1];
      }
      ans = max(ans, n - tmp);
    }
  }
  cout << ans;
  return 0;
}
