#include <bits/stdc++.h>
using namespace std;
const int N = 100005, SQ = 808;
int n, k, dp[2][SQ];
vector<int> A[N];
int main() {
  scanf("%d%d", &n, &k);
  int tot = 0;
  for (int i = 0; i < k; i++) {
    int r, c;
    scanf("%d%d", &r, &c);
    r = n - r + 1;
    if (r >= SQ)
      tot++;
    else
      A[n - c + 1].push_back(r);
  }
  for (int i = 1; i <= n; i++) {
    int w = i & 1, ptr = 0;
    sort(A[i].begin(), A[i].end());
    dp[w][0] = dp[!w][0] + (int)A[i].size() * 3;
    for (int h = 1; h <= min(i, SQ); h++) {
      while (ptr < A[i].size() && A[i][ptr] <= h) ptr++;
      dp[w][0] = min(dp[w][0], dp[!w][h - 1] + ((int)A[i].size() - ptr) * 3 +
                                   h * (h + 1) / 2 + 2);
    }
    ptr = 0;
    for (int j = 1; j < min(i, SQ); j++) {
      while (ptr < A[i].size() && A[i][ptr] <= j) ptr++;
      dp[w][j] = min(dp[w][0], dp[!w][j - 1] + ((int)A[i].size() - ptr) * 3);
    }
  }
  return !printf("%d\n", dp[n & 1][0] + tot * 3);
}
