#include <bits/stdc++.h>
using namespace std;
int coun[5006][5006];
int main() {
  int n, q, l[5006], r[5006], tot = 0;
  vector<int> v[5006];
  cin >> n >> q;
  for (int i = 1; i <= q; i++) cin >> l[i] >> r[i];
  for (int i = 1; i <= q; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      if (v[j].size() < 3) v[j].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (v[i].size() == 1) {
      tot++;
      for (int k = 1; k <= q; k++) {
        if (k != v[i][0]) {
          coun[v[i][0]][k]++;
          coun[k][v[i][0]]++;
        }
      }
    } else if (v[i].size() == 2) {
      tot++;
      coun[v[i][0]][v[i][1]]++;
      coun[v[i][1]][v[i][0]]++;
    } else if (v[i].size() != 0)
      tot++;
  }
  int ans = INT_MAX - 10000;
  for (int i = 1; i <= q; i++)
    for (int j = 1; j <= q; j++)
      if (i != j) ans = min(ans, coun[i][j]);
  cout << tot - ans;
}
