#include <bits/stdc++.h>
const double PI = 3.141592653589793238463;
using namespace std;
inline long long add(long long a, long long b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
inline long long sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += 1000000007;
  return a;
}
inline long long mul(long long a, long long b) {
  return (long long)((long long)a * b % 1000000007);
}
long long fast_power(long long base, long long power) {
  long long result = 1;
  while (power > 0) {
    if (power % 2 == 1) {
      result = (result * base);
    }
    base = (base * base);
    power = power / 2;
  }
  return result;
}
long long min(long long a, long long b) { return a > b ? b : a; }
long long max(long long a, long long b) { return a > b ? a : b; }
void SieveOfEratosthenes(long long n, unordered_set<long long> &s) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long p = 2; p <= n; p++)
    if (prime[p]) s.insert(p);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  {
    long long n, q;
    cin >> n >> q;
    vector<long long> a(n + 2, 0);
    vector<long long> oc(n + 2, 0);
    vector<pair<long long, long long>> v(q);
    for (long long i = 0; i < q; i++) {
      cin >> v[i].first >> v[i].second;
      a[v[i].first] += 1;
      a[v[i].second + 1] -= 1;
    }
    for (long long i = 1; i <= n; i++) {
      a[i] = a[i] + a[i - 1];
    }
    long long ans = 0;
    for (long long i = 0; i < q - 1; i++) {
      for (long long j = v[i].first; j <= v[i].second; j++) {
        a[j]--;
      }
      long long tmp = 0;
      for (long long j = 0; j < n + 2; j++) {
        oc[j] = 0;
      }
      for (long long j = 1; j <= n; j++) {
        if (a[j] > 0) tmp += 1;
        if (a[j] == 1) oc[j] = 1;
      }
      for (long long j = 1; j <= n; j++) {
        oc[j] += oc[j - 1];
      }
      long long mn;
      for (long long j = i + 1; j < q; j++) {
        if (j == i + 1) {
          mn = oc[v[j].second] - oc[v[j].first - 1];
        } else {
          mn = min(oc[v[j].second] - oc[v[j].first - 1], mn);
        }
      }
      ans = max(ans, tmp - mn);
      for (long long j = v[i].first; j <= v[i].second; j++) {
        a[j]++;
      }
    }
    cout << ans << "\n";
  }
}
