#include <bits/stdc++.h>
using namespace std;
int Enum(int a, int b) { return a * 100002 + b; }
const int oo = 1000000000;
int n, k;
pair<int, int> in[100005];
bitset<780 * 100005> B;
int main() {
  scanf("%d%d", &n, &k);
  int R = 0;
  for (int i = (int)(0); i < (int)(k); ++i) {
    scanf("%d%d", &in[i].first, &in[i].second);
    int r = n + 1 - in[i].first;
    if (r > 775)
      R += 3;
    else {
      --r;
      --in[i].second;
      int t = Enum(r, in[i].second);
      B[t] = 1;
    }
  }
  vector<int> V1(776);
  for (int c = n - 1; c >= 0; --c) {
    vector<int> V2(776);
    int Tmp = oo;
    int Cnt = 0;
    for (int r = 775; r >= 0; --r) {
      if (r == 0) {
        V2[0] = min(Tmp, Cnt * 3 + V1[0]);
      } else {
        V2[r] = min(Tmp, Cnt * 3 + V1[r - 1]);
        Cnt += B[Enum(r - 1, c)];
      }
      Tmp = min(Tmp, V2[r] + r * (r + 1) / 2 + 2);
    }
    swap(V1, V2);
  }
  printf("%d\n", R + V1[0]);
  return 0;
}
