#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 1;
const int maxn = 1e5 + 5;
int n, k, high, f[2];
vector<int> p[maxn], g[2];
void Input() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int x, y;
    cin >> x >> y;
    p[y].push_back(x);
  }
}
void Solve() {
  for (int i = 1; i <= n; i++) sort(p[i].begin(), p[i].end());
  high = (int)sqrt(6 * k);
  f[0] = 0;
  g[0].push_back(0);
  for (int i = 1; i <= n; i++) {
    int id = i % 2, c = p[n - i + 1].size() - 1;
    f[id] = f[1 - id] + 3 * (c + 1);
    for (int j = 1; j <= min(i, high); j++) {
      while (c >= 0 && p[n - i + 1][c] > n - j) c--;
      f[id] = min(f[id], 2 + j * (j + 1) / 2 + 3 * (c + 1) + g[1 - id][j - 1]);
    }
    c = p[n - i + 1].size() - 1;
    g[id].clear();
    g[id].push_back(f[id]);
    for (int j = 1; j <= min(i, high); j++) {
      while (c >= 0 && p[n - i + 1][c] > n - j) c--;
      g[id].push_back(inf);
      g[id][j] = min(g[id][j - 1], g[1 - id][j - 1] + 3 * (c + 1));
    }
    p[n - i + 1].clear();
  }
  cout << f[n % 2];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  Input();
  Solve();
}
