#include <bits/stdc++.h>
using namespace std;
long long keep[50001];
long long C[50001];
long long B[50001];
int main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > v;
  for (int i = 0; i < m; i++) {
    long long a, b;
    scanf("%lld", &a);
    scanf("%lld", &b);
    keep[a]++;
    keep[b + 1]--;
    v.push_back(make_pair(a, b));
  }
  for (long long i = 1; i <= n; i++) {
    keep[i] += keep[i - 1];
  }
  long long c = 0;
  for (long long i = 1; i <= n; i++) {
    if (keep[i] == 1) {
      B[i] = 1;
    }
    if (keep[i] == 2) {
      C[i] = 1;
    }
    if (keep[i]) {
      c++;
    }
  }
  for (long long i = 1; i <= n; i++) {
    C[i] += C[i - 1];
    B[i] += B[i - 1];
  }
  long long mn = 0;
  for (long long i = 0; i < m; i++) {
    for (long long j = i + 1; j < m; j++) {
      long long l1 = v[i].first;
      long long r1 = v[i].second;
      long long l2 = v[j].first;
      long long r2 = v[j].second;
      long long l = max(l1, l2);
      long long r = min(r1, r2);
      long long ans;
      if (r >= l) {
        ans = c - (B[r1] - B[l1 - 1]) - (B[r2] - B[l2 - 1]) - (C[r] - C[l - 1]);
      } else {
        ans = c - (B[r1] - B[l1 - 1]) - (B[r2] - B[l2 - 1]);
      }
      mn = max(ans, mn);
    }
  }
  cout << mn << endl;
}
