#include <bits/stdc++.h>
using namespace std;
const int INF = 0x1fffffff;
const int MAXN = 50100;
pair<int, int> a[MAXN];
int b[MAXN];
int c[MAXN];
int d[MAXN];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a[i].first >> a[i].second;
    b[a[i].first]++;
    b[a[i].second + 1]--;
  }
  sort(a, a + m);
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    b[i] += b[i - 1];
    if (b[i]) sum++;
    c[i] = c[i - 1];
    d[i] = d[i - 1];
    if (b[i] == 1) c[i]++;
    if (b[i] == 2) d[i]++;
  }
  int ans = 0;
  for (int i = 0; i < m; ++i) {
    for (int j = i + 1; j < m; ++j) {
      if (a[j].first >= a[i].first && a[j].first <= a[i].second) {
        if (a[j].second >= a[i].second)
          ans = max(ans, sum - c[a[j].second] + c[a[i].first - 1] -
                             d[a[i].second] + d[a[j].first - 1]);
        else
          ans = max(ans, sum - c[a[i].second] + c[a[i].first - 1] -
                             d[a[j].second] + d[a[j].first - 1]);
      } else {
        ans = max(ans, sum - c[a[j].second] + c[a[j].first - 1] -
                           c[a[i].second] + c[a[i].first - 1]);
      }
    }
  }
  cout << ans << endl;
}
