#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, SQ = 780;
const long long inf = 1e18;
long long dp[2][SQ];
vector<int> v[maxn];
int n, m;
long long ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if ((a = n + 1 - a) >= (SQ - 1))
      ans += 3;
    else
      v[b].push_back(a);
  }
  for (int i = 1; i < SQ; i++) dp[0][i] = inf;
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i & 1][SQ - 1] = inf;
    sort(v[i].begin(), v[i].end());
    int num = 0;
    for (int j = SQ - 2; j >= 0; j--) {
      dp[i & 1][j] = min(dp[i & 1][j + 1],
                         num + min(dp[(i + 1) & 1][0] + (j == 0 ? 0 : 2) +
                                       1ll * ((j * (j + 1)) / 2),
                                   dp[(i + 1) & 1][j + 1]));
      if (!v[i].empty() && v[i].back() == j) num += 3, v[i].pop_back();
    }
  }
  ans += dp[n & 1][0];
  printf("%lld\n", ans);
}
