354_D. Transferring Pyramid_8804
Vasya and Petya are using an interesting data storing structure: a pyramid.

The pyramid consists of n rows, the i-th row contains i cells. Each row is shifted half a cell to the left relative to the previous row. The cells are numbered by integers from 1 to <image> as shown on the picture below.

An example of a pyramid at n = 5 is: 

<image>

This data structure can perform operations of two types: 

  1. Change the value of a specific cell. It is described by three integers: "t i v", where t = 1 (the type of operation), i — the number of the cell to change and v the value to assign to the cell. 
  2. Change the value of some subpyramid. The picture shows a highlighted subpyramid with the top in cell 5. It is described by s + 2 numbers: "t i v1 v2 ... vs", where t = 2, i — the number of the top cell of the pyramid, s — the size of the subpyramid (the number of cells it has), vj — the value you should assign to the j-th cell of the subpyramid. 



Formally: a subpyramid with top at the i-th cell of the k-th row (the 5-th cell is the second cell of the third row) will contain cells from rows from k to n, the (k + p)-th row contains cells from the i-th to the (i + p)-th (0 ≤ p ≤ n - k).

Vasya and Petya had two identical pyramids. Vasya changed some cells in his pyramid and he now wants to send his changes to Petya. For that, he wants to find a sequence of operations at which Petya can repeat all Vasya's changes. Among all possible sequences, Vasya has to pick the minimum one (the one that contains the fewest numbers).

You have a pyramid of n rows with k changed cells. Find the sequence of operations which result in each of the k changed cells being changed by at least one operation. Among all the possible sequences pick the one that contains the fewest numbers.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 105).

The next k lines contain the coordinates of the modified cells ri and ci (1 ≤ ci ≤ ri ≤ n) — the row and the cell's number in the row. All cells are distinct.

Output

Print a single number showing how many numbers the final sequence has.

Examples

Input

4 5
3 1
3 3
4 1
4 3
4 4


Output

10


Input

7 11
2 2
3 1
4 3
5 1
5 2
5 5
6 4
7 2
7 3
7 4
7 5


Output

26

Note

One of the possible solutions of the first sample consists of two operations:

2 4 v4 v7 v8

2 6 v6 v9 v10

The picture shows the changed cells color-highlighted. The subpyramid used by the first operation is highlighted blue and the subpyramid used by the first operation is highlighted yellow: 

<image>
#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
vector<int> sc[100005];
long long dp[2][100005];
long long sss(int c, int num) {
  if (sc[c].empty()) return 0;
  return upper_bound(sc[c].begin(), sc[c].end(), num) - sc[c].begin();
}
void cal() {
  for (int(i) = 0; (i) < (int)(2); (i)++)
    for (int(j) = 0; (j) < (int)(100005); (j)++) dp[i][j] = 3 * k;
  if (!sc[n].empty() && sc[n].back() == n)
    dp[1][0] = 3;
  else
    dp[1][0] = 0;
  dp[1][1] = 0;
  long long M = sqrt(k * 6);
  int T = 1;
  for (int i = 2; i <= n; i++) {
    T ^= 1;
    dp[T][0] = 3 * k;
    for (int kk = 0; kk <= i; kk++) {
      long long tmp = kk >= 1 ? dp[T ^ 1][kk - 1] : dp[T ^ 1][0];
      if (kk) {
        long long y = kk * (kk + 1) / 2 + 2;
        if (y > 3 * k) break;
        tmp += y;
      }
      tmp += sss(n + 1 - i, n - kk) * 3;
      dp[T][0] = min(dp[T][0], tmp);
    }
    for (int j = 1; j <= i && j <= M; j++) {
      dp[T][j] = 3 * k;
      dp[T][j] =
          min(dp[T][j - 1], dp[T ^ 1][j - 1] + sss(n + 1 - i, n - j) * 3);
    }
  }
  cout << dp[T][0] << endl;
}
int main() {
  scanf("%d%d", &n, &k);
  int r, c;
  for (int(i) = 0; (i) < (int)(k); (i)++) {
    scanf("%d%d", &r, &c);
    sc[c].push_back(r);
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (!sc[i].empty()) {
      sort(sc[i].begin(), sc[i].end());
    }
  cal();
  return 0;
}
