#include <bits/stdc++.h>
using namespace std;
long long inf = 2147483647;
const long long ll = 9223372036854775807, ninf = 1000000000;
const double eps = 1e-6;
const long long nll = 1000000000000000000;
int num[5005][5005][2] = {};
int A[5005] = {};
pair<int, int> pos[5005] = {};
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.second == b.second) {
    return a.first < b.first;
  }
  return a.second < b.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int a, b;
  while (cin >> a >> b) {
    for (int i = 0; i < b; i++) {
      int x, y;
      cin >> x >> y;
      pos[i].first = x, pos[i].second = y;
      for (int j = x; j <= y; j++) {
        A[j]++;
      }
    }
    for (int i = 1; i <= a; i++) {
      for (int j = i; j <= a; j++) {
        num[i][j][0] = num[i][j - 1][0];
        num[i][j][1] = num[i][j - 1][1];
        if (A[j] == 1) {
          num[i][j][0]++;
        }
        if (A[j] == 2) {
          num[i][j][1]++;
        }
      }
    }
    int res = 0;
    int ans = 0;
    for (int i = 1; i <= a; i++) {
      if (A[i]) ans++;
    }
    sort(pos, pos + b, cmp);
    for (int i = 0; i < b; i++) {
      for (int j = i + 1; j < b; j++) {
        if (pos[j].first > pos[i].second) {
          res = max(res, ans - num[pos[i].first][pos[i].second][0] -
                             num[pos[j].first][pos[j].second][0]);
        } else {
          int t1 = max(pos[i].first, pos[j].first),
              t2 = min(pos[i].second, pos[j].second);
          int t3 = min(pos[i].first, pos[j].first),
              t4 = min(pos[i].second, pos[j].second);
          res = max(res, ans - num[t3][pos[i].second - 1][0] -
                             num[t4 + 1][pos[j].second][0] - num[t1][t2][1]);
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
