// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=2e5+10,INF=0x3f3f3f3f;

int n,q,op,x;

ll now;

struct segtree{

	int n;

	struct node{int l,r,mx,cnt,se;}e[N<<2];

	#define l(p) e[p].l

	#define r(p) e[p].r

	#define m(p) e[p].mx

	#define c(p) e[p].cnt

	#define s(p) e[p].se

	void up(int p){

        c(p)=0;

        m(p)=max(m(p<<1),m(p<<1|1));

        s(p)=max(s(p<<1),s(p<<1|1));

        if(m(p<<1)!=m(p<<1|1))s(p)=max(s(p),min(m(p<<1),m(p<<1|1)));

        if(m(p<<1)==m(p))c(p)+=c(p<<1);

        if(m(p<<1|1)==m(p))c(p)+=c(p<<1|1);

	}

	void bld(int p,int l,int r){

		l(p)=l;r(p)=r;c(p)=-1;

		if(l==r){m(p)=n;s(p)=-1;c(p)=1;return;}

		int mid=l+r>>1;

		bld(p<<1,l,mid);bld(p<<1|1,mid+1,r);

		up(p);

	}

	void MIN(int p,int v){

        if(v>=m(p))return;

        m(p)=v;

	}

	void init(int _n){n=_n;bld(1,1,n);}

	void psd(int p){

        MIN(p<<1,m(p));

        MIN(p<<1|1,m(p));

    }

    void Min(int p,int ql,int qr,int v){

        if(v>=m(p))return;

        if(ql<=l(p)&&r(p)<=qr&&s(p)<v){

            MIN(p,v);

            return;

        }

        psd(p);

		int mid=l(p)+r(p)>>1;

        if(ql<=mid)Min(p<<1,ql,qr,v);

		if(qr>mid)Min(p<<1|1,ql,qr,v);

		up(p);

    }

	int ask(int p,int x){

		if(l(p)==r(p))return m(p);

		int mid=l(p)+r(p)>>1;

		psd(p);

		int ans=0;

		if(x<=mid)ans=ask(p<<1,x);

		else ans=ask(p<<1|1,x);

		up(p);

		return ans;

	}

}row,col;

int main(){

    scanf("%d%d",&n,&q);

    now=1ll*(n-2)*(n-2);

    row.init(n);

    col.init(n);

    for(int i=1;i<=q;++i){

        scanf("%d%d",&op,&x);

        if(op==1){

            int pos=col.ask(1,x);

            now-=pos-2;

            row.Min(1,1,pos-1,x);

        }

        else{

            int pos=row.ask(1,x);

            now-=pos-2;

            col.Min(1,1,pos-1,x);

        }

    }

    printf("%lld\n",now);

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=2e5+10,INF=0x3f3f3f3f;

int n,q,op,x;

ll now;

struct segtree{

	int n;

	struct node{int l,r,mn;}e[N<<2];

	#define l(p) e[p].l

	#define r(p) e[p].r

	#define m(p) e[p].mn

	void bld(int p,int l,int r){

		l(p)=l;r(p)=r;m(p)=n;

		if(l==r){return;}

		int mid=l+r>>1;

		bld(p<<1,l,mid);bld(p<<1|1,mid+1,r);

	}

	void init(int _n){n=_n;bld(1,1,n);}

    void Min(int p,int ql,int qr,int v){

        if(ql<=l(p)&&r(p)<=qr){

            m(p)=min(m(p),v);

            return;

        }

		int mid=l(p)+r(p)>>1;

        if(ql<=mid)Min(p<<1,ql,qr,v);

		if(qr>mid)Min(p<<1|1,ql,qr,v);

    }

	int ask(int p,int x){

		if(l(p)==r(p))return m(p);

		int mid=l(p)+r(p)>>1;

		int ans=m(p);

		if(x<=mid)ans=min(ans,ask(p<<1,x));

		else ans=min(ans,ask(p<<1|1,x));

		return ans;

	}

}row,col;

int main(){

    scanf("%d%d",&n,&q);

    now=1ll*(n-2)*(n-2);

    row.init(n);

    col.init(n);

    for(int i=1;i<=q;++i){

        scanf("%d%d",&op,&x);

        if(op==1){

            int pos=col.ask(1,x);

            now-=pos-2;

            row.Min(1,1,pos-1,x);

        }

        else{

            int pos=row.ask(1,x);

            now-=pos-2;

            col.Min(1,1,pos-1,x);

        }

    }

    printf("%lld\n",now);

    return 0;

}


// Fastest known solution for this problem: