#include <bits/stdc++.h>
using namespace std;
pair<int, int> dat[100000];
int n, k;
int dt[100001];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &dat[i].second, &dat[i].first);
  }
  sort(dat, dat + k);
  memset(dt, -1, sizeof(dt[0]) * n);
  int prevmin = 0;
  int jmin = max(0, (int)(n - sqrt(6 * k) - 4));
  int p = 0;
  for (int i = 0; i < n; i++) {
    int pcnt = 0;
    int newmin = INT_MAX;
    if (jmin > 0) jmin--;
    while (p < k && dat[p] < make_pair(i + 1, i + 1)) p++;
    for (int j = jmin; j <= n - i; j++) {
      while (p < k && dat[p] < make_pair(i + 1, i + j + 1)) p++, pcnt++;
      int newval = prevmin + 2 + (n - i - j + 1) * (n - i - j) / 2;
      if (j == n - i) newval = prevmin;
      if (dt[j] != -1 && newval > dt[j]) newval = dt[j];
      newval += pcnt * 3;
      dt[j] = newval;
      newmin = min(newmin, newval);
    }
    prevmin = newmin;
  }
  printf("%d\n", prevmin);
  return 0;
}
