#include <bits/stdc++.h>
using namespace std;
int n, m, res;
int A[5005], L[5005], R[5005];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (0); i < (m); i++) scanf("%d %d", &L[i], &R[i]);
  for (int i = (0); i < (m); i++) {
    for (int j = (1); j <= (n); j++) A[j] = 0;
    for (int j = (0); j < (m); j++) {
      if (i == j) continue;
      A[L[j]]++;
      A[R[j] + 1]--;
    }
    int tmp = 0;
    for (int j = (1); j <= (n); j++) A[j] += A[j - 1];
    for (int j = (1); j <= (n); j++)
      if (A[j] > 0) tmp++;
    for (int j = (1); j <= (n); j++)
      if (A[j] != 1) A[j] = 0;
    for (int j = (1); j <= (n); j++) A[j] += A[j - 1];
    for (int j = (0); j < (m); j++) {
      if (i == j) continue;
      int cover = tmp - (A[R[j]] - A[L[j] - 1]);
      res = max(res, cover);
    }
  }
  printf("%d\n", res);
  return 0;
}
