#include <bits/stdc++.h>
using namespace std;
int n, m;
struct nod {
  int x, y;
  inline bool operator<(const nod& b) const {
    return (y < b.y || (y == b.y && x < b.x));
  }
} a[100005];
int nn, f[805], h[805];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &a[i].x, &a[i].y);
  sort(a + 1, a + m + 1);
  memset(f, 0x3f, sizeof f);
  f[0] = 0;
  nn = 795;
  for (int i = 1; i <= m; i++) {
    memset(h, 0x3f, sizeof h);
    for (int j = 0; j <= nn; j++)
      if (f[j] < 0x3f3f3f3f) {
        int tmp = max(0, j - a[i].y + a[i - 1].y);
        h[tmp] = min(h[tmp], f[j]);
      }
    memset(f, 0x3f, sizeof f);
    if (a[i].y != a[i - 1].y) {
      int mi = 0x3f3f3f3f;
      for (int j = 0; j <= nn; j++) mi = min(mi, h[j]);
      for (int j = 0; j <= min(n, nn); j++)
        h[j] = min(h[j], mi + j * (j + 1) / 2 + 2);
    }
    for (int j = 0; j <= nn; j++)
      if (h[j] < 0x3f3f3f3f) {
        if (a[i].x + j > n)
          f[j] = min(f[j], h[j]);
        else
          f[j] = min(f[j], h[j] + 3);
      }
  }
  int ans = 0x3f3f3f3f;
  for (int j = 0; j <= nn; j++) ans = min(ans, f[j]);
  printf("%d\n", ans);
  return 0;
}
