#include <bits/stdc++.h>
using namespace std;
const int N = 805;
int n, k;
vector<int> vec[100005];
int f[2][N], sum[100005];
int main() {
  scanf("%d%d", &n, &k);
  int m = (int)(sqrt(6 * k) + 2);
  for (int i = (int)(1); i <= (int)(k); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    vec[n - y + 1].push_back(n - x + 1);
  }
  memset(f, 30, sizeof(f));
  f[0][0] = 0;
  for (int i = (int)(1); i <= (int)(n); i++) {
    int now = i & 1, pre = now ^ 1;
    memset(f[now], 30, sizeof(f[now]));
    for (int j = (int)(1); j <= (int)(m); j++) sum[j] = 1;
    for (auto j : vec[i]) sum[j] = -2;
    for (int j = (int)(1); j <= (int)(m); j++) sum[j] += sum[j - 1];
    int tmp = 1 << 30;
    for (int j = (int)(m); j >= (int)(0); j--) {
      tmp = min(tmp, f[pre][j]);
      f[now][j] =
          min(f[now][j], tmp + sum[j] + (j == 0 ? 0 : 2) + j * (j - 1) / 2);
      if (j)
        f[now][j] = min(f[now][j], f[pre][j - 1] + sum[j] + (j == 1 ? 2 : 0));
    }
  }
  int ans = 0;
  for (int i = (int)(0); i <= (int)(m); i++) ans = min(ans, f[n & 1][i]);
  printf("%d\n", 3 * k + ans);
}
