/*
vectorの配列を吐き出す関数はvfillと同じ要領で簡潔に書けそう
だけど面倒
vfillの範囲指定をできるようにしたい
*/
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx")  //Enable AVX
#pragma GCC optimize("Ofast")
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <iomanip>
#include <functional>
#include <complex>
#include <iostream>
#include <future>
#include <thread>

using namespace std;

using ll=int_fast64_t;
using u64=uint_fast64_t;

using pii=pair<int,int>;
using pil=pair<int,ll>;
using pli=pair<ll,int>;
using pll=pair<ll,ll>;
using psi=pair<string,int>;
using pis=pair<int,string>;
using psl=pair<string,ll>;
using pls=pair<ll,string>;
using pss=pair<string,string>;

//辺 fromあり
template<typename T >
struct Edge {
  int from, to;
  T cost;

  Edge()=default;
  Edge(int _from, int _to, T _cost) : from(_from), to(_to), cost(_cost) {}

  inline bool operator<(const Edge p)const noexcept{
    return cost<p.cost;
  }

  inline bool operator>(const Edge p)const noexcept{
    return cost>p.cost;
  }

};

//辺 fromがない
template<typename T >
struct edge {
  int to;
  T cost;
  edge()=default;
  edge(int _to, T _cost) : to(_to), cost(_cost) {}
};

template<typename T>
using edges=vector<edge<T>>;
template<typename T>
using WeightGraph=vector<edges<T>>;

using Graph=vector<vector<int>>;

template<class T,class U>inline constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>inline constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
#define bit(n,k) ( ( (n)>>(k) )&1 )

inline void bin101(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); 
    cout<<fixed<<setprecision(20);
}

//1-indexed vector cin
template<typename T>
inline void vin1(vector<T> &v){
    for(size_t i=1;i<v.size();i++) cin>>v[i];
}

//0-indexed vector cin
template<typename T>
inline void vin0(vector<T> &v){
    for(size_t i=0;i<v.size();i++) cin>>v[i];
}

//1-indexed vector<vector> cin
template<typename T>
inline void vin1(vector<vector<T>> &v){
    for(size_t i=1;i<v.size();i++){
        for(size_t j=1;j<v[i].size();j++) cin>>v[i][j];
    }
}

//0-indexed vector<vector> cin
template<typename T>
inline void vin0(vector<vector<T>> &v){
    for(size_t i=0;i<v.size();i++){
        for(size_t j=0;j<v[i].size();j++) cin>>v[i][j];
    }
}


bool DEBUG_MODE=false;

#define debug(a) if(DEBUG_MODE){cout<<#a;PRINT(a);cout<<flush;}
#define debug2(a,b) if(DEBUG_MODE){debug(a);debug(b);}
#define debug3(a,b,c) if(DEBUG_MODE){debug(a);debug(b);debug(c);}
#define debug4(a,b,c,d) if(DEBUG_MODE){debug(a);debug(b);debug(c);debug(d);}
#define debug5(a,b,c,d,e) if(DEBUG_MODE){debug(a);debug(b);debug(c);debug(d);debug(e);}

#define gdebug(x) if(DEBUG_MODE){cout<<#x;GPRINT(x);} 

template<class T>void PRINT(const T x){cout<<":"<<x<<"\n";}

//デバッグ
template<typename T>
void PRINT(const vector<T> &v,int a=-1){
    if(!DEBUG_MODE) return;
    cout<<":1d\n";
    for(size_t i=0;i<v.size() and (a<0 or i<=(size_t)a);i++){
        cout<<i<<":"<<v[i]<<'\n';
    }
    cout<<"\n";
}

//デバッグ
template<typename T>
void PRINT(const vector<vector<T>> &v,int a=-1,int b=-1){
    if(!DEBUG_MODE) return;
    cout<<":2d\n";
    for(size_t i=0;i<v.size() and (a<0 or i<=(size_t)a);i++){
        for(size_t j=0;j<v[i].size() and (b<0 or j<=(size_t)b);j++){
            cout<<i<<"-"<<j<<":"<<v[i][j]<<"\n";
        }
    }
    cout<<"\n";
}

//デバッグ
template<typename T>
void PRINT(const vector<vector<vector<T>>> &v,int a=-1,int b=-1,int c=-1){
    if(!DEBUG_MODE) return;
    cout<<":3d\n";
    for(size_t i=0;i<v.size() and (a<0 or i<=(size_t)a);i++){
        for(size_t j=0;j<v[i].size() and (b<0 or j<=(size_t)b);j++){
            for(size_t k=0;k<v[i][j].size() and (c<0 or k<=(size_t)c);k++){
                cout<<i<<"-"<<j<<"-"<<k<<":"<<v[i][j][k]<<"\n";
            }
        }
    }
    cout<<"\n";
}

//デバッグ
template<typename T>
void PRINT(const vector<vector<vector<vector<T>>>> &v,int a=-1,int b=-1,int c=-1,int d=-1){
    if(!DEBUG_MODE) return;
    cout<<":4d\n";
    for(size_t i=0;i<v.size() and (a<0 or i<=(size_t)a);i++){
        for(size_t j=0;j<v[i].size() and (b<0 or j<=(size_t)b);j++){
            for(size_t k=0;k<v[i][j].size() and (c<0 or k<=(size_t)c);k++){
                for(size_t l=0;l<v[i][j][k].size() and (d<0 or l<=(size_t)d);l++){
                    cout<<i<<"-"<<j<<"-"<<k<<"-"<<l<<":"<<v[i][j][k][l]<<"\n";
                }
            }
        }
    }
    cout<<"\n";
}

//デバッグ
template<typename T>
void PRINT(const vector<vector<vector<vector<vector<T>>>>> &v,int a=-1,int b=-1,int c=-1,int d=-1,int e=-1){
    if(!DEBUG_MODE) return;
    cout<<":5d\n";
    for(size_t i=0;i<v.size() and (a<0 or i<=(size_t)a);i++){
        for(size_t j=0;j<v[i].size() and (b<0 or j<=(size_t)b);j++){
            for(size_t k=0;k<v[i][j].size() and (c<0 or k<=(size_t)c);k++){
                for(size_t l=0;l<v[i][j][k].size() and (d<0 or l<=(size_t)d);l++){
                    for(size_t m=0;m<v[i][j][k][l].size() and (e<0 or m<=(size_t)e);m++){
                        cout<<i<<"-"<<j<<"-"<<k<<"-"<<l<<"-"<<m<<":"<<v[i][j][k][l][m]<<"\n";
                    }
                }
            }
        }
    }
    cout<<"\n";
}

template<typename T>
void PRINT(const set<T> &S){
    if(!DEBUG_MODE) return;
    int now=0;
    for(auto x:S){
        cout<<now++<<":"<<x<<"\n";
    }
}

template<typename T,typename U>
void PRINT(const map<T,U> &M){
    if(!DEBUG_MODE) return;
    cout<<":map\n";
    size_t now=0;
    for(auto &x:M){
        cout<<now++<<":"<<x<<"\n";
    }
}


//デバッグ(グリッド)
template<typename T>
void GPRINT(const vector<T> &v,int a=-1){
    if(!DEBUG_MODE) return;
    cout<<":1d\n";
    for(size_t i=0;i<v.size() and (a<0 or i<=(size_t)a);i++){
        if(i) cout<<",";
		cout<<v[i];
    }
}

//デバッグ(グリッド)
template<typename T>
void GPRINT(const vector<vector<T>> &v,int a=-1,int b=-1){
    if(!DEBUG_MODE) return;
    cout<<":2d\n";
    for(size_t i=0;i<v.size() and (a<0 or i<=(size_t)a);i++){
        for(size_t j=0;j<v[i].size() and (b<0 or j<=(size_t)b);j++){
            if(j) cout<<",";
            cout<<v[i][j];
        }
        cout<<"\n";
    }
}

//pair cout
template<typename T, typename U>
inline ostream &operator<<(ostream &os,const pair<T,U> &p) {
  os<<p.first<<" "<<p.second;
  return os;
}

//pair cin
template<typename T, typename U>
inline istream &operator>>(istream &is,pair<T,U> &p) {
  is>>p.first>>p.second;
  return is;
}

//ソート
template<typename T>
inline void vsort(vector<T> &v){
    sort(v.begin(),v.end());
}

//逆順ソート
template<typename T>
inline void rvsort(vector<T> &v){
  sort(v.rbegin(),v.rend());
}

//要素数n 初期値x
template<typename T>
inline vector<T> vmake(size_t n,T x){
  return vector<T>(n,x);
}

//a,b,c,x data[a][b][c] 初期値x
template<typename... Args>
auto vmake(size_t n,Args... args){
    auto v=vmake(args...);
    return vector<decltype(v)>(n,move(v));
}

template<typename T,typename... X>
inline void vfill(T &t,const X... x){
    t=T(x...);
}

template<typename T,typename... X>
void vfill(vector<T> &t,const X... x){
    for(auto &s:t) vfill(s,x...);
}

//最後に改行があるので注意
template<typename T>
void vout(const vector<T> &v,string s=" ",size_t f=0,int t=-1){
    for(size_t i=f;i<v.size() and(t<0 or i<=(size_t)t);i++){
        if(i!=f) cout<<s;
        cout<<v[i];
    }
    cout<<"\n";
}

//最後に改行があるので注意
template<typename T>
void vout(const vector<vector<T>> &v,string s=" ",int fh=0,int th=-1,int fw=0,int tw=-1){
    for(size_t i=fh;i<v.size() and (th<0 or i<=(size_t)th);i++){
        for(size_t j=fw;j<v[i].size() and (tw<0 or j<=(size_t)tw);j++){
            if(j!=fw) cout<<s;
            cout<<v[i][j];
        }
        cout<<"\n";
    }
}

//1ビットの数を返す
inline int popcount(int x){
  return __builtin_popcount(x);
}
//1ビットの数を返す
inline int popcount(ll x){
  return __builtin_popcountll(x);
}

constexpr int MAX=(1<<30)-1;
constexpr ll INF=(1LL<<62)-1;
constexpr ll MOD=1000000000+7;
constexpr int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

template<class T>
struct Compress{
    vector<T> cv; //順番にして重複を消したもの
    bool flag;
    Compress():flag(false){};

    Compress(const vector<T> &v):flag(false){
        add(v);
    }
    int size(){
        return (int)cv.size();
    }
    //vectorを追加
    void add(const vector<T> &v){
        flag=false;
        copy(v.begin(),v.end(),back_inserter(cv));
    }
    //Tを追加
    void add(const T x){
        flag=false;
        cv.emplace_back(x);
    }
    //テーブルを作る O(NlogN)
    void build(){
        flag=true;
        sort(cv.begin(),cv.end());
        cv.erase(unique(cv.begin(),cv.end()),cv.end());
    }
    //vectorの要素を座標圧縮したものを返す O(NlogN)
    vector<int> get(const vector<T> &v) const{
        assert(flag);
        vector<int> ret(v.size());
        for(int i=0;i<v.size();i++) ret[i]=lower_bound(cv.begin(),cv.end(),v[i])-cv.begin();
        return ret;
    }
    //xを座標圧縮したものを返す O(logN)
    int get(const T x)const{
        return lower_bound(cv.begin(),cv.end(),x)-cv.begin();
    }
    //座標圧縮後のkが示す実際の値 O(1)
    T &operator[](int k){
        return cv[k];
    }
};

template<class T,class F>
struct SegmentTree{
    const F f;
    int size;
    vector<T> seg;
    const T unit;

    SegmentTree(int N,const F _f,const T &_unit) :f(_f),unit(_unit){
        size=1;
        while(size<N) size<<=1;
        seg.assign(2*size,unit);
    }
    void set(int k,const T &x){
        seg[k+size]=x;
    }
    void build(){
        for(int k=size-1;k>0;k--){
            seg[k]=f(seg[2*k],seg[2*k+1]);
        }
    }
    void update(int k,const T &x){
        k+=size;
        seg[k]=x;
        while(k>>=1){
            seg[k]=f(seg[2*k],seg[2*k+1]);
        }
    }
    //[a:b)
    T query(int a,int b){
        T L=unit,R=unit;
        for(a+=size,b+=size;a<b;a>>=1,b>>=1){
            if(a&1) L=f(L,seg[a++]);
            if(b&1) R=f(seg[--b],R);
        }
        return f(L,R);
    }

    T operator[](const int &k) const{
        return seg[k+size];
    }
};

void solve(){
    ll N,Q;
    cin>>N>>Q;
    Compress<int> C1,C2;
    vector<int> h,w;
    vector<pii> V;
    
    for(int i=0;i<Q;i++){
        int q,v;
        cin>>q>>v;
        v--;
        V.emplace_back(q,v);
        if(q==1) h.push_back(v);
        else w.push_back(v);
    }
    C1.add(h); C2.add(w);
    C1.add(N-1); C2.add(N-1);
    C1.build(); C2.build();
    auto f=[](int a,int b){
        return min(a,b);
    };
    SegmentTree<int,decltype(f)> seg1(N,f,N-1),seg2(N,f,N-1);
    ll ret=0;
    for(int i=0;i<Q;i++){
        int q,v;
        tie(q,v)=V[i];

        if(q==1){
            int cv=C1.get(v);
            int deep=seg1.query(cv,N);
            ret+=deep-1;
            int c2=C2.get(deep);
            if(seg2[c2]>v){
                seg2.update(c2,v);
            }
        }else{
            int cv=C2.get(v);
            int deep=seg2.query(cv,N);
            ret+=deep-1;
            int c1=C1.get(deep);
            if(seg1[c1]>v){
                seg1.update(c1,v);
            }
        }
    }
    cout<<(N-2)*(N-2)-ret<<endl;
}

int main(){
    DEBUG_MODE=true;
    bin101();
    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    int T=1;
    //cin>>T;
    while(T--) solve();
}

Measured memory_bytes: 11308