#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1, c = getchar();
  while (c < 48) c == '-' && (f = -1), c = getchar();
  while (c > 47) x = x * 10 + c - '0', c = getchar();
  return x * f;
}
const int MAXN = 200005;
std::vector<int> adj[MAXN];
int s[MAXN], f[MAXN];
int n, l, k;
int main(int argc, char const *argv[]) {
  n = read();
  k = read();
  l = sqrt(k * 6);
  for (int i = 1, x, y; i <= k; ++i)
    x = read(), y = read(), adj[y + n - x].push_back(min(n - x, l));
  for (int i = 1, t; i <= n; f[0] = t, ++i) {
    memset(s, 0, (l + 2) << 2);
    for (int y : adj[i]) ++s[y];
    for (int j = l; ~j; --j) s[j] += s[j + 1];
    t = f[0] + s[0] * 3;
    for (int j = min(i, l); j > 0; --j) {
      t = min(t, f[j - 1] + s[j] * 3 + j * (j + 1) / 2 + 2);
      f[j] = min(t, f[j - 1] + s[j] * 3);
    }
  }
  printf("%d\n", f[0]);
  return 0;
}
