#include <bits/stdc++.h>
using namespace std;
int val[800], valant[800];
vector<int> v[1000000];
int n, k;
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int r, c;
    cin >> r >> c;
    v[c].push_back(n + 1 - r);
  }
  for (int iv = 100001; iv > 0; iv--) {
    for (int i = 0; i < 800; i++) valant[i] = val[i];
    vector<int> &w = v[iv];
    sort(w.begin(), w.end());
    int iw = int(w.size()) - 1;
    int mejor = valant[799];
    int vistos = 0;
    for (int i = 799; i > 1; i--) {
      while (iw >= 0 and w[iw] > i) {
        iw--;
        vistos++;
      }
      val[i] = min(2 + i * (i + 1) / 2 + 3 * vistos + mejor,
                   valant[i - 1] + i + 3 * vistos);
      mejor = min(mejor, valant[i - 1]);
    }
    while (iw >= 0 and w[iw] > 1) {
      iw--;
      vistos++;
    }
    mejor = min(mejor, valant[0]);
    val[1] = 3 + 3 * vistos + mejor;
    while (iw >= 0 and w[iw] > 0) {
      iw--;
      vistos++;
    }
    val[0] = 3 * vistos + mejor;
  }
  int sol = 1000000000;
  for (int i = 0; i < 800; i++) sol = min(sol, val[i]);
  cout << sol << endl;
}
