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;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll sum(ll a){
  return a*(a+1)/2;
}

ll sqsum(ll a){
  return a*(a+1)*(2*a+1)/6;
}

ll qsum(ll a){
  return sum(a)*sum(a);
}

ll n,m;
vector<P> qs;
ll cnt[3][50001],cntjust[3][50001];

int main(){
  cin>>n>>m;
  rep(i,m){
    ll q,k;
    cin>>q>>k;
    if(q==0){
      ll lb=0,ub=n+1;
      while(ub-lb>1){
        ll mid=(ub+lb)/2;
        if(sum(mid)<k)lb=mid;
        else ub=mid;
      }
      k=ub;
    }
    if(k>n)continue;
    qs.push_back(P(q,k));
    cnt[q][k]++;
    cntjust[q][k]++;
  }
  rep(i,3)rep(j,n)cnt[i][j+1]+=cnt[i][j];
  m=qs.size();
  ll add=0,sub=0;
  rep(i,m){
    ll q=qs[i].fi,k=qs[i].se;
    if(q==0){
      sub+=k*k;
    }else{
      sub+=sqsum(n)-sqsum(k-1);
    }
  }

  rep(i,m){
    ll q=qs[i].fi,k=qs[i].se;
    if(q==0){
      add+=k*(cnt[1][k]+cnt[2][k]);
    }else if(q==1){
      add+=(sum(n)-sum(k-1))*cnt[2][k-1];
      add+=(sum(n)-sum(k-1))*cntjust[2][k];
    }else if(q==2){
      add+=(sum(n)-sum(k-1))*cnt[1][k-1];
    }
  }

  rep(i,m){
    ll q=qs[i].fi,k=qs[i].se;
    if(q==0){
      sub+=cnt[1][k]*cnt[2][k];
    }
  }

  cout<<qsum(n)+add-sub<<endl;
  return 0;
}