#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define ll long long
#define INF 2000000000
#define INF2 2000000000000000000
 
using namespace std;

int n, q;
ll sum = 0;
int rtree[800001];
int ctree[800001];
int rlazy[800001];
int clazy[800001];

void Create(int node, int start, int end){
	if(start == end) {
		rtree[node] = ctree[node] = n;
		rlazy[node] = clazy[node] = n + 1;
	}
	else {
		int mid = (start + end)/2;
		Create(2*node, start, mid);
		Create(2*node + 1, mid + 1, end);
		rtree[node] = ctree[node] = n;
		rlazy[node] = clazy[node] = n + 1;
	}
}

void updateR(int node, int start, int end, int l, int r, int val) {
	if(rlazy[node] != n + 1) {
		rtree[node] = min(rtree[node], rlazy[node]);
		if(start != end) {
			rlazy[2*node] = min(rlazy[2*node], rlazy[node]);
			rlazy[2*node + 1] = min(rlazy[2*node + 1], rlazy[node]);
		}
		rlazy[node] = n + 1;
	}
	if(start > end or start > r or end < l or l > r)
		return;
	if(start >= l && end <= r) {
		rtree[node] = min(rtree[node], val);
		if(start != end) {
			rlazy[2*node] = min(rlazy[2*node], val);
			rlazy[2*node + 1] = min(rlazy[2*node + 1], val);
		}
		return;
	}
	int mid = (start + end)/2;
	updateR(2*node, start, mid, l, r, val);
	updateR(2*node + 1, mid + 1, end, l, r, val);
	rtree[node] = min(rtree[2*node], rtree[2*node + 1]);
}

void updateC(int node, int start, int end, int l, int r, int val) {
	if(clazy[node] != n + 1) {
		ctree[node] = min(ctree[node], clazy[node]);
		if(start != end) {
			clazy[2*node] = min(clazy[2*node], clazy[node]);
			clazy[2*node + 1] = min(clazy[2*node + 1], clazy[node]);
		}
		clazy[node] = n + 1;
	}
	if(start > end or start > r or end < l or l > r)
		return;
	if(start >= l && end <= r) {
		ctree[node] = min(ctree[node], val);
		if(start != end) {
			clazy[2*node] = min(clazy[2*node], val);
			clazy[2*node + 1] = min(clazy[2*node + 1], val);
		}
		return;
	}
	int mid = (start + end)/2;
	updateC(2*node, start, mid, l, r, val);
	updateC(2*node + 1, mid + 1, end, l, r, val);
	ctree[node] = min(ctree[2*node], ctree[2*node + 1]);
}

int queryR(int node, int start, int end, int l, int r) {
	if(start > end or start > r or end < l or l > r)
		return n + 1;
	if(rlazy[node] != n + 1) {
		rtree[node] = min(rtree[node], rlazy[node]);
		if(start != end) {
			rlazy[2*node] = min(rlazy[2*node], rlazy[node]);
			rlazy[2*node + 1] = min(rlazy[2*node + 1], rlazy[node]);
		}
		rlazy[node] = n + 1;
	}
	if(start >= l && end <= r)
		return rtree[node];
	int mid = (start + end)/2;
	int p = queryR(2*node, start, mid, l, r);
	int q = queryR(2*node + 1, mid + 1, end, l, r);
	return min(p, q);
}

int queryC(int node, int start, int end, int l, int r) {
	if(start > end or start > r or end < l or l > r)
		return n + 1;
	if(clazy[node] != n + 1) {
		ctree[node] = min(ctree[node], clazy[node]);
		if(start != end) {
			clazy[2*node] = min(clazy[2*node], clazy[node]);
			clazy[2*node + 1] = min(clazy[2*node + 1], clazy[node]);
		}
		clazy[node] = n + 1;
	}
	if(start >= l && end <= r)
		return ctree[node];
	int mid = (start + end)/2;
	int p = queryC(2*node, start, mid, l, r);
	int q = queryC(2*node + 1, mid + 1, end, l, r);
	return min(p, q);
}

int main() {
    
    IOS;
   	cin >> n >> q;
   	Create(1,1,n);

   	while(q--) {
   		int type, x;
   		cin >> type >> x;
   		if(type == 1) {
   			int rmin = queryC(1,1,n,x,x);
   			if(rmin == 1)
   				continue;
   			sum += rmin - 2;
   			updateC(1,1,n,x,x,1);
   			updateR(1,1,n,1,rmin - 1, x);
   		}
   		else {
   			int cmin = queryR(1,1,n,x,x);
   			if(cmin == 1)
   				continue;
   			sum += cmin - 2;
   			updateR(1,1,n,x,x,1);
   			updateC(1,1,n,1,cmin - 1, x);
   		}
   	}
   	ll val = (1LL * (n - 2) * (n - 2));
   	val -= sum;
   	cout << val;
}

Measured memory_bytes: 11728