#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, ans = 0;
  ;
  cin >> n >> q;
  vector<int> val(n + 1), pre(n + 1);
  vector<pair<int, int>> arr(q);
  for (int i = 0; i < q; i++) {
    cin >> arr[i].first >> arr[i].second;
    for (int j = arr[i].first; j <= arr[i].second; j++) val[j]++;
  }
  for (int j = 0; j < q; j++) {
    pre.clear();
    pre.resize(n + 1);
    int count = 0;
    for (int i = 1; i < arr[j].first; i++) {
      if (val[i] == 1) pre[i] = 1;
      if (val[i]) count++;
    }
    for (int i = arr[j].first; i <= arr[j].second; i++) {
      if (val[i] == 2) pre[i] = 1;
      if (val[i] > 1) count++;
    }
    for (int i = arr[j].second + 1; i <= n; i++) {
      if (val[i] == 1) pre[i] = 1;
      if (val[i]) count++;
    }
    for (int i = 1; i <= n; i++) pre[i] += pre[i - 1];
    for (int k = j + 1; k < q; k++) {
      int extra = pre[arr[k].second] - pre[arr[k].first - 1];
      ans = max(ans, count - extra);
    }
  }
  cout << ans << endl;
}
