#include <bits/stdc++.h>
using namespace std;
int pre[5000], l[5000], r[5000], cnt[5000];
int ans, sum;
int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= q; i++) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++) {
      cnt[j]++;
    }
  }
  for (int i = 1; i <= q; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      cnt[j]--;
    }
    sum = 0;
    for (int j = 1; j <= n; j++) {
      if (cnt[j] == 1) {
        pre[j] = pre[j - 1] + 1;
      } else {
        pre[j] = pre[j - 1];
      }
      if (cnt[j]) {
        sum++;
      }
    }
    for (int j = i + 1; j <= q; j++) {
      ans = max(ans, sum - pre[r[j]] + pre[l[j] - 1]);
    }
    for (int j = l[i]; j <= r[i]; j++) {
      cnt[j]++;
    }
  }
  cout << ans << endl;
  return 0;
}
