#include <bits/stdc++.h>
using namespace std;
int const N = 3e5, oo = 1e9;
long long const OO = 2e18;
double const eps = 1e-8, PI = acos(-1);
int mod = oo + 7;
int n, q, crc[5222], cum[5222];
pair<int, int> aa[5001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cin >> aa[i].first >> aa[i].second;
    cum[aa[i].first]++, cum[aa[i].second + 1]--;
  }
  int emp = 0, an = n;
  for (int i = 1; i <= n; i++) {
    cum[i] += cum[i - 1];
    emp += cum[i] == 0;
  }
  for (int i = 0; i < q; i++) {
    int l = aa[i].first, r = aa[i].second;
    for (int j = l; j <= r; j++)
      if (cum[j] == 1) crc[i]++;
  }
  for (int i = 0; i < q; i++) {
    int l = aa[i].first, r = aa[i].second;
    vector<int> v;
    for (int j = l; j <= r; j++)
      if (cum[j] == 2) v.push_back(j);
    for (int j = i + 1; j < q; j++) {
      l = aa[j].first, r = aa[j].second;
      auto e = lower_bound(v.begin(), v.end(), l);
      int res = emp + crc[i] + crc[j];
      if (e == v.end() || *e > r)
        ;
      else {
        auto ee = upper_bound(v.begin(), v.end(), r);
        res += ee - e;
      }
      an = min(an, res);
    }
  }
  cout << n - an;
  return 0;
}
