#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101010;
int n, k;
int f[MAXN];
class Change {
 public:
  int x, y;
} a[MAXN];
int ans = 0;
bool cmp(const Change &a, const Change &b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; ++i) {
    scanf("%d%d", &a[i].y, &a[i].x);
    a[i].y = n - a[i].y + 1;
  }
  sort(a + 1, a + k + 1, cmp);
  memset(f, 31, sizeof(f));
  f[0] = 0;
  int cur = 0;
  int cnt = 0;
  int min1;
  int maxto = sqrt(k * 6) + 1;
  for (int i = 1; i <= n; ++i) {
    while (cur < k && a[cur + 1].x < i) cur++;
    cnt = 0;
    f[0] = min(f[0], f[1]);
    min1 = f[0];
    for (int j = 1; j <= maxto; ++j) {
      min1 = min(min1, f[j + 1]);
      if (cur < k && a[cur + 1].x == i && a[cur + 1].y == j) {
        cur++;
        cnt++;
      }
      f[j] = min(f[j + 1], min1 + 2 + ((j * (j + 1)) >> 1));
      f[j] -= cnt * 3;
    }
  }
  ans = min(f[0], f[1]) + k * 3;
  printf("%d\n", ans);
  return 0;
}
