#include <bits/stdc++.h>
using namespace std;
long long n, q, x, y, bio[10000], koliko[100000], resenje = 0;
pair<long long, long long> p[100000];
set<long long> s[10000];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cin >> x >> y;
    p[i] = {x, y};
    for (int j = x; j <= y; j++) bio[j]++;
  }
  for (int i = 0; i < q; i++) {
    long long temp = 0;
    for (long long j = p[i].first; j <= p[i].second; j++) {
      if (bio[j] == 1)
        temp++;
      else if (bio[j] == 2)
        s[i].insert(j);
    }
    koliko[i] = temp;
  }
  for (int i = 1; i <= n; i++) {
    if (bio[i]) resenje++;
  }
  long long vrati = 0;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < q; j++) {
      if (i == j) continue;
      long long o = 0;
      for (auto k : s[i]) {
        if (s[j].count(k)) o++;
      }
      vrati = max(vrati, resenje - (o + koliko[i] + koliko[j]));
    }
  }
  cout << vrati;
  return 0;
}
