#include <bits/stdc++.h>
using namespace std;
int n, q, f, s;
int a[5005], l[5005], r[5005], qz[5005];
int main() {
  cin >> n >> q;
  int nn = 0;
  for (int i = 0; i < q; ++i) {
    cin >> l[i] >> r[i];
    a[l[i]]++;
    a[r[i] + 1]--;
  }
  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    if (a[i]) nn++;
  }
  int ans = 1000000;
  for (int i = 0; i < q - 1; ++i) {
    int summ = 0;
    for (int j = 1; j <= n; ++j) {
      if (j >= l[i] && j <= r[i]) {
        summ += (a[j] == 1);
        qz[j] = qz[j - 1] + (a[j] == 2);
      } else
        qz[j] = qz[j - 1] + (a[j] == 1);
    }
    for (int j = i + 1; j < q; ++j) {
      int aa = qz[r[j]] - qz[l[j] - 1];
      ans = summ + aa < ans ? summ + aa : ans;
    }
  }
  cout << nn - ans << endl;
  return 0;
}
