#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
int main() {
  int n, m, l[maxn], r[maxn], cnt[maxn] = {0}, tot = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &l[i], &r[i]);
    for (int j = l[i]; j <= r[i]; j++) {
      cnt[j]++;
    }
  }
  for (int i = 1; i <= n; i++)
    if (cnt[i]) tot++;
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int sum[maxn], cnti = 0;
    memcpy(sum, cnt, sizeof cnt);
    for (int j = l[i]; j <= r[i]; j++) sum[j]--;
    for (int j = 1; j <= n; j++)
      if (sum[j]) cnti++;
    for (int j = 1; j <= n; j++) sum[j] = sum[j] == 1 ? 1 : 0;
    for (int j = 1; j <= n; j++) sum[j] += sum[j - 1];
    for (int j = i + 1; j < m; j++) {
      int cntj = sum[r[j]] - sum[l[j] - 1];
      ans = max(ans, cnti - cntj);
    }
  }
  cout << ans;
  return 0;
}
