#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
const int M = 100000 + 5;
const int L = 800;
const int INF = 1 << 30;
int n, m, f[2][L + 5], cnt[L + 5];
pair<int, int> p[M];
inline void cmin(int& x, int y) {
  if (y < x) x = y;
}
int main() {
  int x, y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    p[i] = make_pair(x - y + 1, y);
  }
  sort(p + 1, p + m + 1);
  for (int i = 1, j, k = 1, l, t, now, lst; i <= n; ++i) {
    l = min(L, n - i + 1);
    now = i & 1;
    lst = !now;
    memset(cnt, 0, sizeof cnt);
    memset(f[now], 0, sizeof f[now]);
    for (; k <= m && p[k].first == i; ++k)
      ++cnt[min(n - i + 1 - p[k].second + 1, l + 1)];
    for (j = l; ~j; --j) cnt[j] += cnt[j + 1];
    for (j = 0, t = f[lst][0]; j <= l; ++j) {
      f[now][j] = t + j * (j + 1) / 2 + (j ? 2 : 0) + cnt[j + 1] * 3;
      if (f[lst][j + 1]) cmin(f[now][j], f[lst][j + 1] + cnt[j + 1] * 3);
      cmin(t, f[lst][j + 1]);
    }
  }
  printf("%d\n", min(f[n & 1][0], f[n & 1][1]));
  return 0;
}
