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