#include <bits/stdc++.h>
using namespace std;
struct ii {
  int x, y;
} a[100005];
int n, m, i, j, k, cnt[1005], dp[2][1005], lim;
bool cmp(ii x, ii y) { return x.x < y.x; }
int main() {
  scanf("%d%d", &n, &m);
  for ((i) = 1; (i) <= (m); (i)++) {
    scanf("%d%d", &a[i].x, &a[i].y);
    a[i].x = a[i].x - a[i].y + 1;
  }
  lim = sqrt(m * 6) + 1;
  sort(a + 1, a + m + 1, cmp);
  memset(dp, 0x3f, sizeof(dp));
  dp[0][0] = m * 3;
  k = 1;
  for ((i) = 1; (i) <= (n); (i)++) {
    memset(cnt, 0, sizeof(cnt));
    memset(dp[i & 1], 0x3f, sizeof(dp[i & 1]));
    int ry = n - i + 1;
    while (k <= m && a[k].x == i) {
      if (ry - a[k].y + 1 <= lim) cnt[ry - a[k].y + 1]++;
      k++;
    }
    for ((j) = (2); (j) <= (lim); (j)++) cnt[j] += cnt[j - 1];
    for ((j) = 0; (j) <= (lim); (j)++)
      dp[i & 1][j] = dp[(i - 1) & 1][j + 1] - cnt[j] * 3;
    dp[i & 1][0] = min(dp[i & 1][0], dp[(i - 1) & 1][0]);
    int mi = 0x3f3f3f3f;
    for ((j) = 0; (j) <= (lim); (j)++) {
      mi = min(mi, dp[(i - 1) & 1][j]);
      dp[i & 1][j] = min(dp[i & 1][j], mi + j * (j + 1) / 2 + 2 - cnt[j] * 3);
    }
  }
  cout << min(dp[n & 1][0], dp[n & 1][1]) << endl;
  return 0;
}
