#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcountll(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}


typedef tree<pii, null_type, less<pii>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

const int N=2e5+5;
int st_row[4*N];
int st_col[4*N];
int row[N],col[N];

void build(int l,int r,int node,int type)
{
	if(l==r)
	{
		if(type)
			st_row[node]=row[l];
		else
			st_col[node]=col[l];
		return ;
	}

	int mid=(l+r)/2;
	build(l,mid,2*node,type);
	build(mid+1,r,2*node+1,type);
	if(type)
		st_row[node]=max(st_row[2*node],st_row[2*node+1]);
	else
		st_col[node]=max(st_col[2*node],st_col[2*node+1]);
}

void update(int l,int r,int id,int node,int type,int val)
{
	if(l==r)
	{
		if(type)
			st_row[node]=row[l];
		else
			st_col[node]=col[l];
		return;
	}

	int mid=(l+r)/2;
	if(id<=mid)
		update(l,mid,id,2*node,type,val);
	else
		update(mid+1,r,id,2*node+1,type,val);

	if(type)
		st_row[node]=max(st_row[2*node],st_row[2*node+1]);
	else
		st_col[node]=max(st_col[2*node],st_col[2*node+1]);
}

int query(int l,int r,int ql,int qr,int node,int type)
{
	//trace3(l,r,node);
	if(l>qr or r<ql)
		return -1e18;

	if(ql<=l and r<=qr)
	{
		if(type)
			return st_row[node];
		else
			return st_col[node];
	}

	int mid=(l+r)/2;
	int p=query(l,mid,ql,qr,2*node,type);
	int q=query(mid+1,r,ql,qr,2*node+1,type);

	return max(p,q);
}


int32_t main()
{
	fast;
	int n,q;cin>>n>>q;
	int tmp=q;
	MSET(row,-1);
	MSET(col,-1);
	build(2,n-1,1,1);
	build(2,n-1,1,0);

	//trace1(q);

	while(q--)
	{
		int t,x;cin>>t>>x;
		if(t==1)
		{
			int low=2,high=n-1;
			int id=n-1;
			while(low<=high)
			{
				int mid=(low+high)/2;
				int val=query(2,n-1,low,mid,1,1);
				if(val>=x)
				{
					id=mid-1;
					high=mid-1;
				}
				else
					low=mid+1;
			}

			col[x]=id;
			update(2,n-1,x,1,0,col[x]);
		}
		else
		{
			int low=2,high=n-1;
			int id=n-1;
			while(low<=high)
			{
				int mid=(low+high)/2;
				int val=query(2,n-1,low,mid,1,0);
				if(val>=x)
				{
					id=mid-1;
					high=mid-1;
				}
				else
					low=mid+1;
			}

			row[x]=id;
			update(2,n-1,x,1,1,row[x]);
		}
	}	

	int ans=0;
	for(int i=2;i<n;i++)
	{
		if(row[i]==-1)
			row[i]=1;
		if(col[i]==-1)
			col[i]=1;
		ans+=col[i]-1;
		ans+=row[i]-1;
	}

	/*for(int i=2;i<n;i++)
		trace3(i,row[i],col[i]);*/

	ans+=4*n-4;
	cout<<n*n-ans<<endl;
}


Measured memory_bytes: 14960