#include <bits/stdc++.h>
#pragma comment(linker, "/stack:32000000")
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int maxn = 100010;
vector<int> a[maxn];
const int maxval = 3 * maxn;
const int K = 800;
int dp[2][K];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; ++i) {
    int ri, ci;
    scanf("%d%d", &ri, &ci);
    ri, --ci;
    a[ci].push_back(n - ri + 1);
  }
  for (int i = 0; i < n; ++i) sort(a[i].begin(), a[i].end());
  int cr = 0, nx = 1;
  fill(dp[cr], dp[cr] + K, maxval);
  dp[cr][0] = 0;
  for (int i = n - 1; i >= 0; --i) {
    fill(dp[nx], dp[nx] + K, maxval);
    int pos = 0;
    for (int j = 0; j < K; ++j) {
      while (pos < int((a[i]).size()) && a[i][pos] <= j) ++pos;
      if (dp[cr][j] == maxval) continue;
      if (j + 1 < K)
        dp[nx][j + 1] =
            min(dp[nx][j + 1], dp[cr][j] + 3 * (int((a[i]).size()) - pos));
      int toval = dp[cr][j] + (j > 0) * (j * (j + 1) / 2 + 2) +
                  3 * (int((a[i]).size()) - pos);
      dp[nx][0] = min(dp[nx][0], toval);
      if (j + 1 < K) dp[cr][j + 1] = min(dp[cr][j + 1], dp[cr][j]);
    }
    swap(cr, nx);
  }
  printf("%d\n", dp[cr][0]);
  return 0;
}
