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>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
vector<ll> tate;
vector<ll> yoko;
bool flag[50005];
ll len[50005];
ll rect[50005];

int main(void){
	for(ll i=1;i<=50000;i++){
		len[i]=len[i-1]+i;
	}
	for(ll i=1;i<=50000;i++){
		rect[i]=rect[i-1]+i*i;
	}
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		ll q,k;
		scanf("%lld%lld",&q,&k);
		k--;
		if(q==2){
			if(k<n)flag[k]=true;
		}
		if(q==0){
			if(k<len[n])tate.push_back(k);
		}
		if(q==1){
			if(k<n)yoko.push_back(k);
		}
	}
	sort(tate.begin(),tate.end());
	sort(yoko.begin(),yoko.end());
	ll dec=0;
	ll ans=0;
	ll cnt_ty=(ll)0;
	for(int i=0;i<tate.size();i++){
		int lv=upper_bound(len,len+n,tate[i])-len;
		int l2=lower_bound(yoko.begin(),yoko.end(),lv)-yoko.begin();
		dec+=lv;
		cnt_ty+=l2;
	}
	for(int i=0;i<yoko.size();i++){
		dec+=len[n]-len[yoko[i]];
	}
	ll po=0;
	int i_t=0,i_y=0;
	for(int i=0;i<n;i++){
		while(i_t<tate.size() && tate[i_t]<len[i]){
			int lv=upper_bound(len,len+n,tate[i_t])-len;
			int l2=lower_bound(yoko.begin(),yoko.end(),lv)-yoko.begin();
			dec-=lv;
			cnt_ty-=l2;
			i_t++;
		}
		while(i_y<yoko.size() && yoko[i_y]<i){
			i_y++;
		}
		dec-=(ll)(i)*i_y;
		if(flag[i])continue;
		ll val=rect[n]-rect[i];
		val-=dec;
		val+=cnt_ty;
		ans+=val;
		//printf("%lld %lld %lld\n",rect[n]-rect[i],dec,(ll)cnt_ty);
	}
	printf("%lld\n",ans);
	return 0;
}