#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

ll N, Q;

pair<ll, ll> QUERY[200005];

int main(){
	cin >> N >> Q;

	rep(i, Q) {
		cin >> QUERY[i].first >> QUERY[i].second;
		QUERY[i].second--;
	}
	ll ans =  (N-2) * (N-2);

	set<ll> yokoset;
	set<ll> tateset;
	map<ll, ll> yokomemo;
	map<ll, ll> tatememo;

	yokoset.insert(N);
	tateset.insert(N);
	yokomemo[N] = N - 2;
	tatememo[N] = N - 2;

	rep(i, Q) {
		ll pos = QUERY[i].second;

		if(QUERY[i].first == 1) {
			//下に行く
			ll haba = tatememo[*tateset.lower_bound(pos)];

			//cout << "get " << haba << endl;
			ans -= haba;

			ll curyoko = yokomemo[*yokoset.lower_bound(haba)];
			if(curyoko < pos - 1) continue;
			yokoset.insert(haba);
			yokomemo[haba] = pos - 1;
		} else {
			//右に行く
			ll haba = yokomemo[*yokoset.lower_bound(pos)];

			//cout << "get " << haba << endl;
			ans -= haba;

			ll curtate = tatememo[*tateset.lower_bound(haba)];
			if(curtate < pos - 1) continue;
			tateset.insert(haba);
			tatememo[haba] = pos - 1;
		}
	}
	cout << ans << endl;
}
