#include <iostream>
#include <vector>
using namespace std;
const int INF = 1001001001;

template<class M, class L> struct LazyPropagationSegmentTree
{
	int n;
	int size;
	int log_n;
	vector<M> data;
	vector<L> lazy;
	const function<M(M, M)> f_m;
	const M e_m;
	const function<L(L, L)> f_l;
	const L e_l;
	const function<M(M, L)> f;
	const function<L(L, int)> p;

	LazyPropagationSegmentTree(int n, function<M(M, M)> f_m, M e_m, function<L(L, L)> f_l, L e_l, function<M(M, L)> f, function<L(L, int)> p) : n(n), f_m(f_m), e_m(e_m), f_l(f_l), e_l(e_l), f(f), p(p) {
		size = 1;
		log_n = 0;
		while (size < n) size <<= 1, log_n++;
		data.assign(size * 2, e_m);
		lazy.assign(size * 2, e_l);
	}

	void init(const vector<M> &init_vals) {
		data.assign(size * 2, e_m);
		for (int i = 0; i < init_vals.size(); i++) data[size+i] = init_vals[i];
		for (int i = size-1; i > 0; i--) data[i] = f_m(data[2*i], data[2*i+1]);
	}

	void eval(int k, int len) {
		if (lazy[k] == e_l) return;
		if (k < size) {
			lazy[2*k] = f_l(lazy[2*k], lazy[k]);
			lazy[2*k + 1] = f_l(lazy[2*k + 1], lazy[k]);
		}
		data[k] = f(data[k], p(lazy[k], len));
		lazy[k] = e_l;
	}

	void update(int l, int r, L l_prop) {
		update_aux(l, r, l_prop, 1, 0, size);
	}

	void update_aux(int l, int r, L l_prop, int k, int k_l, int k_r) {
		eval(k, k_r - k_l);
		if (r <= k_l || k_r <= l) return;
		else if (l <= k_l && k_r <= r) {
			lazy[k] = f_l(lazy[k], l_prop);
			eval(k, k_r - k_l);
		} else {
			update_aux(l, r, l_prop, 2*k, k_l, (k_l + k_r) / 2);
			update_aux(l, r, l_prop, 2*k + 1, (k_l + k_r) / 2, k_r);
			data[k] = f_m(data[2*k], data[2*k + 1]);
		}
	}

	M query_all() {
		eval(1, size);
		return data[1];
	}

	M query(int l, int r) {
		return query_aux(l, r, 1, 0, size);
	}

	M query_aux(int l, int r, int k, int k_l, int k_r) {
		eval(k, k_r - k_l);
		if (r <= k_l || k_r <= l) return e_m;
		else if (l <= k_l && k_r <= r) return data[k];
		else {
			M vl = query_aux(l, r, k*2, k_l, (k_l + k_r) / 2);
			M vr = query_aux(l, r, k*2 + 1, (k_l + k_r) / 2, k_r);
			return f_m(vl, vr);
		}
	}

	int find_max_right(int l, const function<bool(M)> &g) {
		if (l == n) return n;
		l += size;
		M s = e_m;
		for (int i = log_n, len = size; i >= 0; i--, len >>= 1) eval(l>>i, len);
		int len = 1;
		while (true) {
			while (l % 2 == 0) l >>= 1, len <<= 1;
			eval(l, len);
			if (!g(f_m(s, data[l]))) break;
			s = f_m(s, data[l]);
			l++;
			if ((l & -l) == l) return n;
		}
		while (l < size) {
			l = 2 * l, len >>= 1;
			eval(l, len);
			if (g(f_m(s, data[l]))) {
				s = f_m(s, data[l]);
				l++;
			}
		}
		return l - size;
	}

	int find_min_left(int r, const function<bool(M)> &g) {
		if (r == 0) return 0;
		r += size;
		M s = e_m;
		for (int i = log_n, len = size; i >= 0; i--, len >>= 1) eval((r-1)>>i, len);
		int len = 1;
		while (true) {
			r--;
			while (r > 1 && (r % 2)) r >>= 1, len <<= 1;
			eval(r, len);
			if (!g(f_m(data[r], s))) break;
			s = f_m(data[r], s);
			if ((r & -r) == r) return 0;
		}
		while (r < size) {
			r = 2 * r + 1, len >>= 1;
			eval(r, len);
			if (g(f_m(data[r], s))) {
				s = f_m(data[r], s);
				r--;
			}
		}
		return r + 1 - size;
	}

	void eval_all() {
		int len = size, j = 2;
		for (int i = 1; i < 2*size; i++) {
			if (i == j) j *= 2, len /= 2;
			eval(i, len);
		}
	}

	M val(int idx) {
		return data[size + idx];
	}

	vector<M> val_vec() {
		vector<M> res(n);
		for (int i = 0; i < n; i++) res[i] = data[size+i];
		return res;
	}
};

int main() {
	long long n, Q;
	cin >> n >> Q;
	using M = int;
	using L = int;
	M e_m = INF;
	L e_l = INF;
	auto f_m = [&](M m1, M m2) -> M {
		return min(m1, m2);
	};
	auto f_l = [&](L l1, L l2) -> L {
		return min(l1, l2);
	};
	auto f = [&](M m, L l) -> M {
		return min(m, l);
	};
	auto p = [&](L l, int len) -> L {
		return l;
	};
	LazyPropagationSegmentTree<M, L> x(n, f_m, e_m, f_l, e_l, f, p), y(n, f_m, e_m, f_l, e_l, f, p);
	vector<M> initv(n-1, n-1);
	initv[0] = e_m;
	x.init(initv); y.init(initv);
	long long ans = (n-2) * (n-2);
	for (int q = 0; q < Q; q++) {
		int t, val;
		scanf("%d%d", &t, &val);
		val--;
		if (t == 1) {
			int a = x.query(val, val+1);
			ans -= a - 1;
			x.update(val, val+1, 1);
			y.update(1, a, val);
		} else {
			int a = y.query(val, val+1);
			ans -= a - 1;
			y.update(val, val+1, 1);
			x.update(1, a, val);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11736