#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, inf = 1e9 + 7;
long long n, k, i, j;
long long C[N], f[3][N];
pair<long long, long long> A[N];
inline long long util(long long a, long long b, long long c) {
  return f[c][a] - f[c][b];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long i, j, a, b, ans = 0, m, temp, c, d, e, ff, cur = 0;
  cin >> n >> k;
  for (i = 0; i < k; i++) {
    cin >> A[i].first >> A[i].second;
    C[A[i].first]++;
    C[A[i].second + 1]--;
  }
  sort(A, A + k);
  for (i = 1; i < n + 2; i++) C[i] += C[i - 1];
  for (i = 1; i < n + 1; i++)
    if (C[i]) cur++;
  for (i = 1; i < n + 1; i++)
    for (j = 1; j < 3; j++)
      if (C[i] == j) f[j][i]++;
  for (i = 1; i < n + 1; i++)
    for (j = 1; j < 3; j++) f[j][i] += f[j][i - 1];
  temp = 0;
  for (i = 0; i < k; i++)
    for (j = i + 1; j < k; j++) {
      if (A[i].second < A[j].first) {
        temp = cur - util(A[i].second, A[i].first - 1, 1) -
               util(A[j].second, A[j].first - 1, 1);
      } else if (A[i].second <= A[j].second) {
        a = A[i].first - 1;
        b = A[j].first - 1;
        c = A[j].first - 1;
        d = A[i].second;
        e = A[i].second;
        ff = A[j].second;
        temp = cur - util(b, a, 1) - util(d, c, 2) - util(ff, e, 1);
      } else {
        a = A[i].first - 1;
        b = A[j].first - 1;
        c = A[j].first - 1;
        d = A[j].second;
        e = A[j].second;
        ff = A[i].second;
        temp = cur - util(b, a, 1) - util(d, c, 2) - util(ff, e, 1);
      }
      ans = max(ans, temp);
    }
  cout << ans;
}
