#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int main() {
  srand(1373737);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, q;
  cin >> n >> q;
  vector<pair<int, int> > arr(q);
  for (int i = 0; i < q; i++) {
    cin >> arr[i].first >> arr[i].second;
    arr[i].first--;
    arr[i].second--;
  }
  vector<vector<int> > have(n);
  vector<int> cnt(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < q; j++) {
      if (arr[j].first <= i && i <= arr[j].second) {
        cnt[i]++;
        if (cnt[i] < 3) have[i].push_back(j);
      }
    }
  }
  vector<int> kek1(q);
  vector<vector<int> > kek2(q, vector<int>(q));
  int zero = 0;
  for (int i = 0; i < n; i++) {
    if (cnt[i] >= 3) continue;
    if (cnt[i] == 0) zero++;
    if (cnt[i] == 1) kek1[have[i].back()]++;
    if (cnt[i] == 2) kek2[have[i][0]][have[i][1]]++;
  }
  int ans = 0;
  for (int i = 0; i < q; i++) {
    for (int j = i + 1; j < q; j++) {
      int cur = n - zero - kek1[i] - kek1[j] - kek2[i][j];
      ans = max(ans, cur);
    }
  }
  cout << ans;
  return 0;
}
