#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
const long long INF = ~0ULL >> 1;
template <class T>
inline void read(T &n) {
  char c;
  for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar())
    ;
  n = c - '0';
  for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - '0';
}
int Pow(int base, int n, int mo) {
  if (n == 0) return 1;
  if (n == 1) return base % mo;
  int tmp = Pow(base, n >> 1, mo);
  tmp = (long long)tmp * tmp % mo;
  if (n & 1) tmp = (long long)tmp * base % mo;
  return tmp;
}
const int maxk = 800;
const int maxn = 120000;
int n, m;
int r[maxn], c[maxn], v[maxk + 10];
int dp[2][maxk + 10];
vector<int> E[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (m); ++i) {
    scanf("%d%d", &r[i], &c[i]);
    int x = n - c[i] + 1;
    int y = n - r[i] + 1;
    E[x].push_back(y);
  }
  for (int i = (1); i <= (n); ++i) {
    int cur = i & 1, las = (i - 1) & 1;
    memset(dp[cur], 0x7f, sizeof(dp[cur]));
    memset(v, 0, sizeof(v));
    int cnt = 0;
    for (int j = (0); j < (E[i].size()); ++j)
      if (E[i][j] > maxk)
        cnt++;
      else
        v[E[i][j]] = 1;
    for (int k = (min(i, maxk)); k >= (0); --k) {
      int tmp = dp[las][max(k - 1, 0)];
      if (k > 0) tmp += 2 + k * (k + 1) / 2;
      tmp += 3 * cnt;
      dp[cur][0] = min(dp[cur][0], tmp);
      if (k) dp[cur][k] = dp[las][k - 1] + cnt * 3;
      if (v[k]) cnt++;
    }
    for (int k = (1); k <= (min(i, maxk)); ++k)
      dp[cur][k] = min(dp[cur][k], dp[cur][k - 1]);
  }
  printf("%d\n", dp[n & 1][0]);
  return 0;
}
