#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const long long INF64 = 1e18;
const long double EPS = 1e-12;
const long double PI = acos(-1);
const long long MD = 925262732;
const long long T = 23917;
const int N = 100003;
const int M = 800;
int n, k;
int sum;
vector<int> g[N];
int dp[N], dp1[N];
int get(long long first) { return (first * (first + 1) / 2); }
int main() {
  cin >> n >> k;
  for (int i = 0; i < int(k); i++) {
    int first, second;
    cin >> first >> second;
    if (n - first + 1 > M)
      sum += 3;
    else
      g[second].push_back(n - first + 1);
  }
  for (int i = 1; i <= n; i++) sort((g[i]).begin(), (g[i]).end());
  for (int j = 0; j < int(M + 1); j++) dp[j] = INF;
  int j = 0;
  dp1[0] = dp[0] = int(int((g[1]).size())) * 3;
  for (int i = 1; i <= M; i++) {
    while (j < int((g[1]).size()) && g[1][j] <= i + 1) j++;
    dp1[i] = dp[i] = 2 + get(i + 1) + int(int((g[1]).size()) - j) * 3;
  }
  for (int i = 2; i <= n; i++) {
    int j = 0;
    int q = INF;
    for (int u = 0; u <= M; u++) {
      while (j < int((g[i]).size()) && g[i][j] <= u) j++;
      dp[max(u - 1, 0)] = dp1[u] + int(int((g[i]).size()) - j) * 3;
      q = min(q, dp1[u]);
    }
    j = 0;
    dp[0] = min(dp[0], q + int(int((g[i]).size()) * 3));
    for (int u = 1; u < M; u++) {
      while (j < int((g[i]).size()) && g[i][j] <= u + 1) j++;
      dp[u] = min(dp[u], q + 2 + get(u + 1) + int(int((g[i]).size()) - j) * 3);
    }
    for (int j = 0; j <= M; j++) dp1[j] = dp[j];
  }
  cout << sum + dp[0];
  return 0;
}
