#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
const int N = 1e5 + 100, sq = 800;
int dp[2][sq];
vector<int> ja[N];
int n, q;
int32_t main() {
  memset(dp, 31, sizeof dp);
  dp[0][0] = 0;
  cin >> n >> q;
  for (int i = 1; i <= q; i++) {
    int s, so;
    cin >> s >> so;
    int x = s - so;
    x = n - x;
    ja[x].push_back(s);
  }
  for (int i = 1; i <= n; i++) {
    sort(ja[i].begin(), ja[i].end());
  }
  for (int i = 1; i <= n; i++) {
    if (i < sq) dp[1][i] = 0;
    vector<int> t = ja[i];
    dp[1][0] = dp[1 - 1][0] + ja[i].size() * 3;
    for (int j = 1; j < min(i + 1, sq); j++) {
      if (t.size() && n - t.back() + 1 == j) t.pop_back();
      dp[1][0] = min((int)dp[1][0], (int)dp[1 - 1][j - 1] + (int)t.size() * 3 +
                                        (int)j * (j + 1) / 2 + 2);
    }
    for (int j = 1; j < min(i, sq); j++) {
      if (ja[i].size() && n - ja[i].back() + 1 == j) ja[i].pop_back();
      dp[1][j] = dp[1 - 1][max((int)0, j - 1)] + ja[i].size() * 3;
      dp[1][j] = min(dp[1][j], dp[1][j - 1]);
    }
    for (int j = 0; j < sq; j++) {
      dp[0][j] = dp[1][j];
      dp[1][j] = 1e8;
    }
  }
  cout << dp[0][0];
}
