#include <bits/stdc++.h>
using namespace std;
int paintTheFence(vector<vector<int>>& ranges, int n, int q) {
  vector<int> wall(n + 2, 0);
  vector<int> single(n + 1, 0);
  vector<int> double1(n + 1, 0);
  for (int i = 0; i < q; i++) {
    wall[ranges[i][0]]++;
    wall[ranges[i][1] + 1]--;
  }
  for (int i = 1; i <= n; i++) {
    wall[i] += wall[i - 1];
  }
  int total = n;
  for (int i = 1; i <= n; i++) {
    if (wall[i] == 0) {
      total--;
    } else if (wall[i] == 1) {
      single[i]++;
    } else if (wall[i] == 2) {
      double1[i]++;
    }
    single[i] += single[i - 1];
    double1[i] += double1[i - 1];
  }
  int ans = 0;
  for (int i = 0; i < q; i++) {
    for (int j = i + 1; j < q; j++) {
      int tempans = total - (single[ranges[i][1]] - single[ranges[i][0] - 1]) -
                    (single[ranges[j][1]] - single[ranges[j][0] - 1]);
      int l = max(ranges[i][0], ranges[j][0]);
      int r = min(ranges[i][1], ranges[j][1]);
      if (r >= l) {
        tempans -= double1[r] - double1[l - 1];
        tempans += single[r] - single[l - 1];
      }
      ans = max(ans, tempans);
    }
  }
  return ans;
}
int main() {
  int n, q;
  cin >> n >> q;
  vector<vector<int>> ranges(q, vector<int>(2, 0));
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> ranges[i][j];
    }
  }
  cout << paintTheFence(ranges, n, q) << endl;
}
