Problem: Problem

A-chan, Rika-chan, and Hart-kun came to visit the condominium.
The three decided to sneak into a room where they could manage the electricity in all the rooms and play a trick.

This condominium has the shape of n cubes lined up in a row.
Each cube has one side length increasing by 1 from the west (1,2,3, ..., n), the i-th cube has i floors, and each floor has i x horizontal rooms. There is.
The west side of the second and subsequent cubes borders the east side of one west cube, and the south side of all cubes faces a straight road.



<image>



At first, all rooms have electricity.
Each of the three took the following actions.


* A-chan turned off the lights in all the kth rooms from the west.
* Licca turned off the lights in all the kth rooms from the south.
* Hart turned off the lights in all rooms on the k floor.



Find the number of rooms that are lit after such mischief has been done m times.

Constraints

* 1 ≤ n, m ≤ 50000
* 0 ≤ qi ≤ 2
* 1 ≤ ki ≤ 2 × 109
* The same action can only be given once

Input


n m
q1 k1
...
qm km


All inputs are given as integers.
The number n of cubes and the number m of actions are given in the first line.
The numbers q and k of the person who acted on the second and subsequent lines m are given.

When qi is 0, it means that A-chan, when it is 1, it means that Rika-chan, and when it is 2, it means that Hart-kun has acted.

The three may try to turn off the lights in places where there is no room.

Output

Output the number of rooms with electricity in one line.

Examples

Input

3 1
0 4


Output

27


Input

3 2
2 2
2 3


Output

14

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  LL N, M;
  cin >> N >> M;

  LL ans = 0;
  VL idx = {0ll};
  for(LL i=1,j=1;i<=N;++i){
	ans += i*i*i;
	idx.PB(j);
	j += i;
  }

  VVL qs(3);
  REP(i,M){
	LL Q, K;
	cin >> Q >> K;
	qs[Q].PB(K);
  }
  REP(q,3) SORT(qs[q]);

  VL blk_x;
  REP(i,N+1) blk_x.PB(i);

  for(LL x: qs[0]){
	if(x > N*(N+1)/2) continue;
	LL ix = (--upper_bound(ALL(idx), x)) - begin(idx);
	blk_x[ix]--;
	ans -= ix*ix;
  }

  VL blk_y(N+1);
  for(LL i=1;i<=N;++i)
	blk_y[i] = blk_y[i-1] + i * blk_x[i];

  VL del_y(N+1);
  for(LL y:qs[1]){
	if(y > N) continue;
	ans -= blk_y[N] - blk_y[y-1];
	++del_y[y];
  }

  LL acc = 0;
  VL blk_z(N+1);
  for(LL i=1;i<=N;++i){
	acc += del_y[i];
	blk_z[i] = blk_z[i-1] + (i - acc) * blk_x[i];
  }
  for(LL z: qs[2]){
	if(z > N) continue;
	ans -= blk_z[N] - blk_z[z-1];
  }
  cout << ans << endl;

  return 0;
}