#include <bits/stdc++.h>
using namespace std;
int X;
vector<int> v[100010];
int all, all2;
bool used[800 + 10];
int dp[800 + 10], dp2[800 + 10];
void calc(int x) {
  int i;
  for ((i) = 0; (i) < (int)(800); (i)++) used[i] = false;
  for ((i) = 0; (i) < (int)(v[x].size()); (i)++) used[v[x][i]] = true;
  for ((i) = 0; (i) < (int)(800); (i)++) dp2[i] = (1 << 29);
  int cost = 0;
  for (i = 800 - 1; i >= 0; i--) {
    if (used[i]) cost += 3;
    int tmp = cost + dp[max(i - 1, 0)];
    if (tmp < dp2[i]) dp2[i] = tmp;
    if (i > 0) tmp += i * (i + 1) / 2 + 2;
    if (tmp < dp2[0]) dp2[0] = tmp;
  }
  if (v[x].empty()) all2 = all;
  for ((i) = 0; (i) < (int)(800); (i)++) dp[i] = dp2[i];
  for ((i) = 0; (i) < (int)(800); (i)++) dp[i + 1] = min(dp[i + 1], dp[i]);
}
int main(void) {
  int K, i, j, ans = 0;
  cin >> X >> K;
  for ((i) = 0; (i) < (int)(K); (i)++) {
    int r, c;
    scanf("%d%d", &r, &c);
    int x = c - 1;
    int y = X - r;
    if (y < 800)
      v[x].push_back(y);
    else
      ans += 3;
  }
  for (i = X - 1; i >= 0; i--) calc(i);
  cout << dp[0] + ans << endl;
  return 0;
}
