import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

struct SegTree(T, E)
{
	alias T delegate(T, E) G;
	alias T delegate(E, E) H;
	int n;
	G g; H h;
	T d1; E d0;
	T[] dat; E[] laz;
	this(int _n, G _g, H _h, T _d1, E _d0, T[] v = [])
	{
		g = _g;	h = _h;
		d1 = _d1; d0 = _d0;
		init(_n);
		if (_n == cast(int)v.length) build(_n, v);
	}
	void init(int _n)
	{
		n = 1;
		while (n < _n) n *= 2;
		dat.length = n; dat[] = d1;
		laz.length = 2*n-1; laz[] = d0;
	}
	void build(int _n, T[] v)
	{
		foreach (i; 0.._n) dat[i] = v[i];
	}
	void update(int a, int b, E x, int k, int l, int r)
	{
		if (r <= a || b <= l) return;
		if (a <= l && r <= b)
		{
			laz[k] = h(laz[k], x);
			return;
		}
		update(a, b, x, k*2+1, l, (l+r)/2);
		update(a, b, x, k*2+2, (l+r)/2, r);
	}
	void update(int a, int b, E x)
	{
		update(a, b, x, 0, 0, n);
	}
	T query(int k)
	{
		T c = dat[k];
		k += n-1;
		E x = laz[k];
		while (k > 0)
		{
			k = (k-1)/2;
			x = h(x,laz[k]);
		}
		return g(c,x);
	}
}

void main()
{
	auto N = RD!int;
	auto Q = RD;
	long f(long a, long b)
	{
		return max(a, b);
	}
	auto st1 = new SegTree!(long, long)(N, (long a, long b){return min(a, b);}, (long a, long b){return min(a, b);}, N-1, N-1);
	auto st2 = new SegTree!(long, long)(N, (long a, long b){return min(a, b);}, (long a, long b){return min(a, b);}, N-1, N-1);
	st1.update(0, N-1, N-1);
	st2.update(0, N-1, N-1);
	long cnt;
	foreach (i; 0..Q)
	{
		auto num = RD;
		auto x = RD!int-1;
		if (num == 1)
		{
			auto y = st1.query(x);
			debug writeln("i:", " y:", y);
			cnt += y-1;
			st2.update(0, cast(int)y, x);
		}
		else
		{
			auto y = st2.query(x);
			debug writeln("i:", " y:", y);
			cnt += y-1;
			st1.update(0, cast(int)y, x);
		}
	}
	debug writeln("cnt:", cnt);
	long ans = (cast(long)(N-2))^^2 - cnt;

	writeln(ans);
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 16076