#include <bits/stdc++.h>
using namespace std;
int read() {
  char c;
  int x = 0, flag = 1;
  while ((c = getchar()) && (c < '0' || c > '9'))
    if (c == '-') flag = -1;
  do x = x * 10 + c - '0';
  while ((c = getchar()) && c >= '0' && c <= '9');
  return x * flag;
}
const int maxn = 100010, inf = 0x3f3f3f3f;
int n, m, h, dp[2][maxn], d[2][maxn], sz[maxn], ans = inf;
struct poi {
  int x, y;
} p[maxn];
bool operator<(const poi &a, const poi &b) { return a.y < b.y; }
int main() {
  n = read(), m = read();
  h = (int)sqrt(m * 6);
  for (int i = 1; i <= h; i++) sz[i] = i * (i + 1) / 2;
  for (int i = 1; i <= m; i++) p[i].x = n - read() + 1, p[i].y = read();
  sort(p + 1, p + m + 1);
  int curp = 1, cur = 0;
  for (int i = 1; i <= h + 1; i++) dp[cur][i] = inf;
  dp[cur][0] = 0;
  for (int i = 1; i <= n + 1; i++) {
    cur ^= 1;
    int tot = 0, lim = min(n - i + 1, h), mn = dp[cur ^ 1][0];
    for (int j = 1; j <= lim; j++) d[cur][j] = 0;
    while (curp <= m && p[curp].y <= i) tot++, d[cur][p[curp++].x]++;
    for (int j = 1; j <= lim; j++) d[cur][j] += d[cur][j - 1];
    dp[cur][0] = min(dp[cur ^ 1][0], dp[cur ^ 1][1]) + tot * 3;
    for (int j = 1; j <= lim; j++) {
      mn = min(mn, dp[cur ^ 1][j]);
      dp[cur][j] =
          min(mn + sz[j] + 2, dp[cur ^ 1][j + 1]) + (tot - d[cur][j]) * 3;
    }
    dp[cur][lim + 1] = inf;
  }
  printf("%d\n", dp[cur][0]);
  return 0;
}
