#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, const U &b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, const U &b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T1, class T2>
inline void gn(T1 &x1, T2 &x2) {
  gn(x1), gn(x2);
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
vector<int> vec[100100];
int dp[2][800];
int main() {
  int n, k;
  cin >> n >> k;
  int m = 3 * k;
  int ans = 0;
  for (int i = 0; i < k; i++) {
    int first, second;
    gn(first, second);
    if ((long long)(n + 1 - first) * (n + 2 - first) / 2 + 2 > m)
      ans += 3;
    else
      vec[first - second + 1].push_back(n - first + 1);
  }
  int f = 0;
  memset(dp, 0x3f, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    f ^= 1;
    dp[f][800 - 1] = m;
    sort(vec[i].begin(), vec[i].end());
    int cur = vec[i].size(), k = 0;
    for (int j = 800 - 1; j--;) {
      dp[f][j] = dp[f][j + 1];
      while (cur && vec[i][cur - 1] > j) cur--, k++;
      smin(dp[f][j], dp[f ^ 1][0] + (j ? j * (j + 1) / 2 + 2 : 0) + 3 * k);
      smin(dp[f][j], dp[f ^ 1][j + 1] + 3 * k);
    }
  }
  cout << ans + dp[f][0] << endl;
  return 0;
}
