#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>
#include<time.h>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;
//f***************k
int main() {
	ll N, Q; cin >> N >> Q;
	vector<ll> tate(N + 1), yoko(N + 1);
	ll ans = (N - 2) * (N - 2);
	ll T = N - 3, Y = N - 3;
	for (int i = 0; i < Q; i++) {
		ll ty, x; cin >> ty >> x;
		x -= 2;
		if (ty == 1) {

			for (int j = x; j <= Y; j++) {
				tate[j] = T;
			}
			ans -= tate[x] + 1;
			//printf("tate[%lld]+1=%lld\n", x, tate[x] + 1);
			Y = min(Y, x - 1);
		}

		if (ty == 2) {
			for (int j = x; j <= T; j++) {
				yoko[j] = Y;
			}
			ans -= yoko[x] + 1;
			//printf("yoko[%lld]+1=%lld\n", x, yoko[x] + 1);
			T = min(T, x - 1);

		}
	}
	cout << ans << endl;
}