// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 300005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 200005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
	return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

void buildtree(ll si, ll ss, ll se, vl& segtree, ll n)
{
	if (ss == se)
		segtree[si] = n;
	else
	{
		ll mid = (ss + se) / 2;
		buildtree(2 * si, ss, mid, segtree, n);
		buildtree(2 * si + 1, mid + 1, se, segtree, n);
		segtree[si] = min(segtree[2 * si], segtree[2 * si + 1]);
	}
}
void updatetree(ll si, ll ss, ll se, ll l, ll r, ll val, vl& segtree, vl& lazy)
{
	if (lazy[si] != inf)
	{
		segtree[si] = min(segtree[si], lazy[si]);
		if (ss != se)
			lazy[2 * si] = min(lazy[2 * si], lazy[si]) , lazy[2 * si + 1] = min(lazy[2 * si + 1], lazy[si]);
		lazy[si] = inf;
	}
	if (ss > r || se < l)
		return;
	if (ss >= l && se <= r)
	{
		segtree[si] = min(segtree[si], val);
		if (ss != se)
			lazy[2 * si] = min(lazy[2 * si], val) , lazy[2 * si + 1] = min(lazy[2 * si + 1], val);
		return;
	}
	ll mid = (ss + se) / 2;
	updatetree(2 * si, ss, mid, l, r, val, segtree, lazy);
	updatetree(2 * si + 1, mid + 1, se, l, r, val, segtree, lazy);
	segtree[si] = min(segtree[2 * si], segtree[2 * si + 1]);
}
ll query(ll si, ll ss, ll se, ll l, ll r, vl& segtree, vl& lazy)
{
	if (lazy[si] != inf)
	{
		segtree[si] = min(segtree[si], lazy[si]);
		if (ss != se)
			lazy[2 * si] = min(lazy[2 * si], lazy[si]) , lazy[2 * si + 1] = min(lazy[2 * si + 1], lazy[si]);
		lazy[si] = inf;
	}
	if (ss > r || se < l)
		return inf;
	if (ss >= l && se <= r)
		return segtree[si];
	ll mid = (ss + se) / 2;
	ll left = query(2 * si, ss, mid, l, r, segtree, lazy);
	ll right = query(2 * si + 1, mid + 1, se, l, r, segtree, lazy);
	return min(left, right);
}

signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	fast
	ll n, q;
	cin >> n >> q;
	ll ans = (n - 2) * (n - 2);
	ll ver = n - 1, hor = n - 1;
	map<ll, ll> doneh, donev;
	vl segver(4 * (n + 1)), seghor(4 * (n + 1)), lazyver(4 * (n + 1), inf), lazyhor(4 * (n + 1), inf);
	buildtree(1, 1, n, segver, n);
	buildtree(1, 1, n, seghor, n);
	while (q--)
	{
		ll t, x;
		cin >> t >> x;
		if (t == 1)
		{
			if (donev[x] == 0)
			{
				ll val = query(1, 1, n, x, x, seghor, lazyhor);
				ans -= max(0LL, val - 2);
				updatetree(1, 1, n, 1, val, x, segver, lazyver);
				donev[x] = 1;
			}
		}
		else
		{
			if (doneh[x] == 0)
			{
				ll val = query(1, 1, n, x, x, segver, lazyver);
				ans -= max(0LL, val - 2);
				updatetree(1, 1, n, 1, val, x, seghor, lazyhor);
				doneh[x] = 1;
			}
		}
	}
	cout << ans << END;



// #ifndef ONLINE_JUDGE
//     cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}



Measured memory_bytes: 40600