#include <bits/stdc++.h>
using namespace std;
int getBest(int n, vector<pair<int, int>> &q) {
  unordered_map<int, int> p;
  int total = 0;
  for (auto d : q) {
    for (int i = d.first; i <= d.second; i++) {
      if (p[i] == 0) total++;
      p[i]++;
    }
  }
  int ret = 0;
  for (int i = 0; i < q.size() - 1; i++) {
    int totalCopy = total;
    vector<int> pre(n + 1);
    for (int j = 1; j <= n; j++) {
      pre[j] = pre[j - 1];
      bool collide = (j >= q[i].first) && (j <= q[i].second);
      if (collide && p[j] == 1) {
        totalCopy--;
        continue;
      }
      if (collide && p[j] == 2) {
        pre[j]++;
        continue;
      }
      if (p[j] == 1) pre[j]++;
    }
    int best = 0;
    for (int j = i + 1; j < q.size(); j++) {
      int lost = pre[q[j].second] - pre[q[j].first - 1];
      best = max(best, totalCopy - lost);
    }
    ret = max(ret, best);
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> q;
  for (auto i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    q.push_back({a, b});
  }
  cout << getBest(n, q) << endl;
}
