#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[1000000 + 5];
int dp[1000000 + 5], g[1000000 + 5], n, k, ans = 0;
inline int lowbit(int x) { return x & (-x); }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &a[i].second, &a[i].first);
    a[i].second = n - a[i].second + 1;
  }
  sort(a + 1, a + 1 + k);
  int now = 1;
  for (int i = 1; i <= n; i++) dp[i] = 1e9;
  for (int i = 1; i <= n; i++) {
    int pos = min(1000, n - i + 1), cnt = 0;
    while (now <= k && a[now].first == i) {
      if (a[now].second > pos)
        ans += 3;
      else
        g[a[now].second] = i, cnt++;
      now++;
    }
    int mi = 1e9;
    for (int j = 0; j <= pos; j++) {
      if (g[j] == i) cnt--;
      mi = min(mi, dp[j]);
      dp[j] = min(dp[j], mi + 2 + j * (j + 1) / 2);
      dp[j] += cnt * 3;
    }
    dp[0] = min(dp[0], dp[1]);
    for (int j = 1; j < pos; j++) dp[j] = dp[j + 1];
    dp[pos] = 1e9;
    for (int j = pos; j; j--) dp[j - 1] = min(dp[j - 1], dp[j]);
  }
  printf("%d\n", dp[0] + ans);
  return 0;
}
