#include <bits/stdc++.h>
using std::pair;
using std::string;
using std::vector;
const int oo = 0x3f3f3f3f;
template <typename T>
inline bool chkmax(T &a, T b) {
  return a < b ? a = b, true : false;
}
template <typename T>
inline bool chkmin(T &a, T b) {
  return b < a ? a = b, true : false;
}
string procStatus() {
  std::ifstream t("/proc/self/status");
  return string(std::istreambuf_iterator<char>(t),
                std::istreambuf_iterator<char>());
}
template <typename T>
T read(T &first) {
  int f = 1;
  char ch = getchar_unlocked();
  for (; !isdigit(ch); ch = getchar_unlocked())
    if (ch == '-') f = -1;
  for (first = 0; isdigit(ch); ch = getchar_unlocked())
    first = 10 * first + ch - '0';
  return first *= f;
}
template <typename T>
void write(T first) {
  if (first == 0) {
    putchar_unlocked('0');
    return;
  }
  if (first < 0) {
    putchar_unlocked('-');
    first = -first;
  }
  static char s[20];
  int top = 0;
  for (; first; first /= 10) s[++top] = first % 10 + '0';
  while (top) putchar_unlocked(s[top--]);
}
const int MAXN = 1e5 + 5, MAXK = 1e5 + 5, SIZE = 800;
int N, K;
pair<int, int> A[MAXK];
inline bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second || (a.second == b.second && a.first < b.first);
}
void input() {
  read(N);
  read(K);
  for (int i = 1; i <= K; ++i) {
    read(A[i].first);
    read(A[i].second);
  }
}
void solve() {
  static bool flag[MAXN][SIZE + 1];
  int ans = 0;
  for (int i = 1; i <= K; ++i) {
    int first = A[i].first, second = A[i].second;
    if (N - first + 1 < SIZE)
      flag[second][N - first + 1] = true;
    else
      ans += 3;
  }
  static int dp[SIZE + 1];
  memset(dp, +oo, sizeof(dp));
  dp[0] = 0;
  for (int i = 1; i <= N; ++i) {
    static int cnt[SIZE + 1];
    cnt[SIZE] = 0;
    for (int j = SIZE - 1; j >= 0; --j) {
      cnt[j] = cnt[j + 1] + flag[i][j];
    }
    int mincost = +oo;
    for (int j = 0; j < SIZE; ++j) {
      chkmin(mincost, dp[j]);
      dp[j] = std::min(dp[j + 1], mincost + (j ? j * (j + 1) / 2 + 2 : 0)) +
              cnt[j + 1] * 3;
    }
  }
  ans += *std::min_element(dp, dp + SIZE);
  printf("%d\n", ans);
}
int main() {
  input();
  solve();
  return 0;
}
