#include <bits/stdc++.h>
using namespace std;
const int mxN = 5005;
deque<deque<int> > Painter(mxN);
vector<bool> Painted(mxN);
vector<vector<int> > cnt(mxN, vector<int>(mxN, 0));
int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      if ((int)Painter[j].size() < 3) {
        Painter[j].push_back(i);
      }
      Painted[j] = true;
    }
  }
  int total_sections = 0;
  for (int i = 1; i <= n; i++) {
    total_sections += (Painted[i] == true);
  }
  for (int i = 1; i <= n; i++) {
    if ((int)Painter[i].size() == 3 || (int)Painter[i].size() == 0) {
      continue;
    }
    assert((int)Painter[i].size() < 3);
    if ((int)Painter[i].size() == 1) {
      for (int j = 0; j < q; j++) {
        if (j == Painter[i].back()) {
          continue;
        }
        cnt[Painter[i].back()][j]++;
        cnt[j][Painter[i].back()]++;
      }
    } else {
      cnt[Painter[i].back()][Painter[i].front()]++;
      cnt[Painter[i].front()][Painter[i].back()]++;
    }
  }
  int Min = 1e9;
  for (int i = 0; i < q; i++) {
    for (int j = i + 1; j < q; j++) {
      Min = min(Min, cnt[i][j]);
    }
  }
  assert(Min != 1e9);
  cout << total_sections - Min << "\n";
  return 0;
}
