#include <bits/stdc++.h>
using namespace std;
const int inf_int = 1e9 + 100;
const long long inf_ll = 1e18;
const double pi = 3.1415926535898;
bool debug = 0;
const int MAXN = (2e6) + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (2e6 + 100);
vector<int> pos[MAXN];
const int K = 1000;
int top[K + 2];
void solve() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    int r, c;
    cin >> r >> c;
    pos[c].push_back(n - r + 1);
  }
  vector<int> cur(K, inf_int);
  cur[0] = 0;
  for (int i = 1; i <= n; ++i) {
    vector<int> nxt(K, inf_int);
    memset(top, 0, sizeof top);
    for (int v : pos[i]) {
      top[min(v, K - 1)]++;
    }
    for (int i = K - 1; i >= 1; --i) {
      top[i - 1] += top[i];
    }
    int mn = *min_element(cur.begin(), cur.end());
    for (int i = K - 1; i >= 0; --i) {
      if (i > 0) {
        nxt[i] = mn + top[i + 1] * 3 + 2 + i * (i + 1) / 2;
      } else {
        nxt[i] = mn + top[i + 1] * 3;
      }
    }
    42;
    42;
    for (int i = K - 2; i >= 0; --i) {
      nxt[i] = min(nxt[i], cur[i + 1] + top[i + 1] * 3);
    }
    42;
    swap(cur, nxt);
  }
  cout << *min_element(cur.begin(), cur.end()) << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(15);
  int t = 1;
  while (t--) {
    solve();
  }
  42;
}
