#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
const long long oo = 1e15;
inline void Min(long long& a, long long b) {
  if (b < a) a = b;
}
struct node {
  int i, j;
} a[maxn];
vector<int> V[maxn];
int n, k;
long long mn[2][maxn] = {0};
long long f[2][maxn] = {0};
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    cin >> a[i].i >> a[i].j;
  }
  int bound = sqrt(6 * k);
  long long ret = 0;
  for (int i = 1; i <= k; ++i) {
    if (a[i].i < n - bound + 1)
      ret += 3ll;
    else
      V[a[i].j].push_back(a[i].i);
  }
  for (int i = 1; i <= n; ++i) sort(V[i].begin(), V[i].end());
  for (int j = 0; j <= n + 1; ++j) f[0][j] = oo, mn[0][j] = 0;
  f[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= min(bound, n - i + 1); ++j)
      f[i & 1][j] = oo, mn[i & 1][j] = oo;
    int pt = V[i].size() - 1;
    for (int j = 0; j <= min(bound, n - i + 1); ++j) {
      while (pt >= 0 && V[i][pt] >= n - j + 1) pt--;
      if (j != bound) Min(f[i & 1][j], f[(i - 1) & 1][j + 1] + 3ll * (pt + 1));
      Min(f[i & 1][j], mn[(i - 1) & 1][j] + (long long)j * (j + 1) / 2 +
                           (j == 0 ? 0ll : 2ll) + 3ll * (pt + 1));
      if (j != 0) Min(mn[i & 1][j], mn[i & 1][j - 1]);
      Min(mn[i & 1][j], f[i & 1][j]);
    }
  }
  Min(f[n & 1][0], f[n & 1][1]);
  ret += f[n & 1][0];
  cout << ret << endl;
  return 0;
}
