/***********************************************************
	When you are inspired by passion 
	and you want to live for the current moment

	When your every thought and action
	has the power to become the story of your future

	When difficulties stand to demolish your Glory
	Just remember that Life is a 'Golden adverse Story'

	Withstand it to acheive your passion and dreams
	more amazingly more easily.

	Why then? When writing the story of your Life
	You want to Let someone else hold your pen

					huzaifa242©

***********************************************************/
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define MAX 100005
#define x first 
#define y second

int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = numeric_limits <int>::max())
{return uniform_int_distribution<int> (l, r)(rng);}

template <typename T, typename G>
ostream& operator << (ostream& out, const pair <T, G> &a) 
{return out << "( " << a.x << ", " << a.y << ")";}

template <typename T>
ostream& operator << (ostream& out, const vector <T> &a) 
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

template <typename T>
ostream& operator << (ostream& out, const set <T> &a) 
{out << "{ "; for(const auto &i: a) out << i << ", "; return out << "}" << endl;}

template <typename T, typename G>
ostream& operator << (ostream& out, const map <T, G> &a) 
{out << "< "; for(const auto &i: a) out << i << ", "; return out << ">" << endl;}

template <typename T, size_t N>
typename enable_if<!is_same <typename remove_cv <T>::type, char>::value,
ostream&>::type operator << (ostream& out, T (&a)[N])
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

void debug_out(){cerr << endl;} 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr << (H) << ' '; debug_out(T...);}
 
#ifdef LOCAL
#define debug(...) cerr << '#' << #__VA_ARGS__ << ":\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif

int n;

struct info {
	int v, e;
	bool lz;
};
template <typename T>
class segment_tree {
	#define left_node 2 * node
	#define right_node 2 * node + 1
	private:
	vector <T> tree;
	function <T(T,T)> merge;
	public:
	segment_tree(auto fnc, int size) {
		merge = fnc;
		tree.resize(4 * size);
	}
	segment_tree(auto fnc) {
		merge = fnc;
		tree.resize(4 * MAX);
	}
	void build(int node, int l, int r) {
		if (l > r)
			return;
		if (l == r) {
			tree[node].v = n;
			tree[node].e = n;
			tree[node].lz = false;
			return;
		}
		int m = (l + r) / 2;
		build(left_node, l, m);
		build(right_node, m + 1, r);
		tree[node] = merge(tree[left_node], tree[right_node]);
		return;
	}
	void calclazy(int node, int l, int r, int x, int y) {
		if (!tree[node].lz)
			return;
		tree[node].lz = false;
		tree[node].v = tree[node].e;
		if (l != r) {
			tree[left_node].lz = true;
			tree[right_node].lz = true; 
			tree[left_node].e = tree[node].e;
			tree[right_node].e = tree[node].e;
		}
		tree[node].e = n;
		return;	
	}
	void updateRange(int node, int l, int r, int x, int y, int z) {
		calclazy(node, l, r, x, y);
		if (l > r || x > r || y < l)
			return ; //out of range
		if (l >= x && r <= y) {
			tree[node].lz = true;
			tree[node].e = z;
			calclazy(node, l, r, x, y);
			return;
		}
		int m = (l + r) / 2;
		updateRange(left_node, l, m, x, y, z);
		updateRange(right_node, m + 1, r, x, y, z);
		tree[node] = merge(tree[left_node], tree[right_node]);
		return;
	}
	T query(int node, int l, int r, int x, int y) {
		calclazy(node, l, r, x, y);// Only for Lazy Propogation
		if (l > r || x > r || y < l) {
			T grbg;
			return grbg;
		}
		if (l >= x && r <= y)
			return tree[node];
		int m = (l + r) / 2;
		if (m >= y)
			return query(left_node, l, m, x, y);
		else if (m < x)
			return query(right_node, m + 1, r, x, y); 
		return merge(query(left_node, l, m, x, y), query(right_node, m + 1, r, x, y));
	}
	#undef left_node
	#undef right_node 
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int q;
	cin >> n >> q;
	int ans = (n - 2) * (n - 2);
	int r = n, b = n;
	auto mrg = [&](info p, info q) {
		info r;
		r.v = min(p.v, q.v);
		r.e = n;
		r.lz = false;
		return r;
	};
	vector <int> rows(n + 1, 0), cols(n + 1, 0);
	segment_tree <info> rowr(mrg, n + 1), colb(mrg, n + 1);
	rowr.build(1, 0, n);
	colb.build(1, 0, n);
	rows[0] = rows[n] = cols[0] = cols[n] = 1;
	while (q--) {
		int id, x;
		cin >> id >> x;
		if (id == 1) {
			if (cols[x])
				break;
			ans -= (colb.query(1, 0, n, x, x).v - 2);
			cols[x] = 1;
			if (r > x) {
				rowr.updateRange(1, 0, n, 1, b, x);
				r = x;
			} 
		} else {
			if (rows[x])
				break;
			ans -= (rowr.query(1, 0, n, x, x).v - 2);
			rows[x] = 1;
			if (b > x) {
				colb.updateRange(1, 0, n, 1, r, x);
				b = x;
			}  
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 43848