#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
	int f;char c;
	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>inline void write(T x){
	static char q[64];int cnt=0;
	if(!x)pc('0');if(x<0)pc('-'),x=-x;
	while(x)q[cnt++]=x%10+'0',x/=10;
	while(cnt--)pc(q[cnt]);
}
const int maxn=200005;
int L[maxn],U[maxn];
int main(){
	int n,q,up,le;long long cnt;
	read(n),read(q);up=le=n;
	cnt=1ll*(n-2)*(n-2);
	for(int i=1;i<=q;++i){
		int a,b;read(a),read(b);
		if(a==1){
			if(b>le)
				cnt-=U[b]-2;
			else{
				cnt-=up-2;
				for(int j=le-1;j>b;--j)
					U[j]=up;
				le=b;
			}
		}
		else{
			if(b>up)
				cnt-=L[b]-2;
			else{
				cnt-=le-2;
				for(int j=up-1;j>b;--j)
					L[j]=le;
				up=b;
			}
		}
	}
	write(cnt),pc('\n');
	return 0;
}
