#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <deque>
#include <tuple>
#include <unordered_set>
#include <array>
#include <string>

using namespace std;
#define ll long long
#define ar array

int main() {
	int n, q;
	cin >> n >> q;
	ll ans=1LL*(n-2)*(n-2);
	set<pair<int, int>> se[2];
 	se[0].insert({n, n});
	se[1].insert({n, n});
	while (q--) {
		int t, x;
		cin >> t >> x, t--;
		auto it=se[t].lower_bound({x, -1});
		int k=(*it).second;
		ans-=k-2;
		se[t^1].insert({k, x});
	}
	cout << ans;
	return 0;
}