#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
const int MAXM = 800;
long long dp[2][MAXM + 10], sum[MAXM + 10];
vector<int> vec[MAXN];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (n == 1) {
    printf("%d\n", k * 3);
    return 0;
  }
  int flag = 0;
  for (int i = 0; i < k; i++) {
    int r, c;
    scanf("%d%d", &r, &c);
    vec[c].push_back(n - r + 1);
    if (r == c && c == n) flag = 1;
  }
  long long *dp0 = dp[0], *dp1 = dp[1];
  dp0[0] = 3 * flag;
  dp0[1] = 0;
  for (int i = 2; i <= n; i++) {
    int k2 = n - i + 1;
    sort((vec[k2]).begin(), (vec[k2]).end());
    sum[0] = 0;
    int ptr = 0;
    for (int j = 1; j <= min(MAXM, i); j++) {
      sum[j] = sum[j - 1];
      if (ptr < ((int)(vec[k2]).size()) && vec[k2][ptr] == j) {
        sum[j]++;
        ptr++;
      }
    }
    dp1[0] = ((int)(vec[k2]).size()) * 3 + dp0[0];
    for (int j = 1; j <= min(MAXM - 1, i); j++) {
      dp1[0] = min(dp1[0], dp0[j - 1] + 1ll * j * (j + 1) / 2 + 2 +
                               (((int)(vec[k2]).size()) - sum[j]) * 3);
    }
    for (int j = 1; j <= min(MAXM - 1, i); j++)
      dp1[j] =
          min(dp1[j - 1], dp0[j - 1] + (((int)(vec[k2]).size()) - sum[j]) * 3);
    swap(dp0, dp1);
  }
  printf("%I64d\n", dp0[0]);
  return 0;
}
