// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args)
	{
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
		__f(comma+1, args...);
	}
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 200005;

ll n, q, a[MAXN], b[MAXN], segtree[4 * MAXN], lazy[4 * MAXN], segtree2[4 * MAXN], lazy2[4 * MAXN], ans;

ll combine(ll a, ll b)
{
	return min(a, b);
}

void build(ll node, ll curr_l, ll curr_r)
{
	if(curr_l == curr_r) segtree[node] = a[curr_r]; 
	else
	{
		ll mid = (curr_l + curr_r) >> 1;
		build(2 * node + 1, curr_l, mid);
		build(2 * node + 2, mid + 1, curr_r);
		segtree[node] = combine(segtree[2 * node + 1], segtree[2 * node + 2]);
	}
}

// To add val to range [l .. r]
void range_update(ll node, ll curr_l, ll curr_r, ll update_l, ll update_r, ll val)
{
	if(lazy[node] != 1e18)
	{
		segtree[node] = min(segtree[node], lazy[node]);
		if(curr_l != curr_r)
		{
			lazy[2 * node + 1] = min(lazy[2 * node + 1], lazy[node]);
			lazy[2 * node + 2] = min(lazy[2 * node + 2], lazy[node]);
		} 
		lazy[node] = 1e18;
	}
	if(update_l > update_r || curr_l > curr_r || curr_l > update_r || curr_r < update_l) return;
	if(curr_l >= update_l && curr_r <= update_r)
	{
		segtree[node] = min(segtree[node], val);
		if(curr_l != curr_r)
		{
			lazy[2 * node + 1] = min(lazy[2 * node + 1], val);
			lazy[2 * node + 2] = min(lazy[2 * node + 2], val);
		} 
		return;
	}
	ll mid = (curr_l + curr_r) >> 1;
	range_update(2 * node + 1, curr_l, mid, update_l, update_r, val);
	range_update(2 * node + 2, mid + 1, curr_r, update_l, update_r, val);
	segtree[node] = combine(segtree[2 * node + 1], segtree[2 * node + 2]);
}

ll query(ll node, ll curr_l, ll curr_r, ll query_l, ll query_r)
{
	if(query_l > query_r || curr_l > curr_r || curr_l > query_r || curr_r < query_l) return 1e18;
	if(lazy[node] != 1e18)
	{
		segtree[node] = min(segtree[node], lazy[node]);
		if(curr_l != curr_r)
		{
			lazy[2 * node + 1] = min(lazy[2 * node + 1], lazy[node]);
			lazy[2 * node + 2] = min(lazy[2 * node + 2], lazy[node]);
		}  
		lazy[node] = 1e18;
	}
	if(curr_l >= query_l && curr_r <= query_r) return segtree[node];
	else
	{
		ll mid = (curr_l + curr_r) >> 1;
		ll left_value = query(2 * node + 1, curr_l, mid, query_l, min(query_r, curr_r)); 
		ll right_value = query(2 * node + 2, mid + 1, curr_r, max(query_l, curr_l), query_r);
		return combine(left_value, right_value);
	}
}

ll combine2(ll a, ll b)
{
	return min(a, b);
}

void build2(ll node, ll curr_l, ll curr_r)
{
	if(curr_l == curr_r) segtree2[node] = b[curr_r]; 
	else
	{
		ll mid = (curr_l + curr_r) >> 1;
		build2(2 * node + 1, curr_l, mid);
		build2(2 * node + 2, mid + 1, curr_r);
		segtree2[node] = combine2(segtree2[2 * node + 1], segtree2[2 * node + 2]);
	}
}

// To add val to range [l .. r]
void range_update2(ll node, ll curr_l, ll curr_r, ll update_l, ll update_r, ll val)
{
	if(lazy2[node] != 1e18)
	{
		segtree2[node] = min(segtree2[node], lazy2[node]);
		if(curr_l != curr_r)
		{
			lazy2[2 * node + 1] = min(lazy2[2 * node + 1], lazy2[node]);
			lazy2[2 * node + 2] = min(lazy2[2 * node + 2], lazy2[node]);
		} 
		lazy2[node] = 1e18;
	}
	if(update_l > update_r || curr_l > curr_r || curr_l > update_r || curr_r < update_l) return;
	if(curr_l >= update_l && curr_r <= update_r)
	{
		segtree2[node] = min(segtree2[node], val);
		if(curr_l != curr_r)
		{
			lazy2[2 * node + 1] = min(lazy2[2 * node + 1], val);
			lazy2[2 * node + 2] = min(lazy2[2 * node + 2], val);
		} 
		return;
	}
	ll mid = (curr_l + curr_r) >> 1;
	range_update2(2 * node + 1, curr_l, mid, update_l, update_r, val);
	range_update2(2 * node + 2, mid + 1, curr_r, update_l, update_r, val);
	segtree2[node] = combine2(segtree2[2 * node + 1], segtree2[2 * node + 2]);
}

ll query2(ll node, ll curr_l, ll curr_r, ll query_l, ll query_r)
{
	if(query_l > query_r || curr_l > curr_r || curr_l > query_r || curr_r < query_l) return 1e18;
	if(lazy2[node] != 1e18)
	{
		segtree2[node] = min(segtree2[node], lazy2[node]);
		if(curr_l != curr_r)
		{
			lazy2[2 * node + 1] = min(lazy2[2 * node + 1], lazy2[node]);
			lazy2[2 * node + 2] = min(lazy2[2 * node + 2], lazy2[node]);
		}  
		lazy2[node] = 1e18;
	}
	if(curr_l >= query_l && curr_r <= query_r) return segtree2[node];
	else
	{
		ll mid = (curr_l + curr_r) >> 1;
		ll left_value = query2(2 * node + 1, curr_l, mid, query_l, min(query_r, curr_r)); 
		ll right_value = query2(2 * node + 2, mid + 1, curr_r, max(query_l, curr_l), query_r);
		return combine2(left_value, right_value);
	}
}


int main()
{
	FAST_IO;

 	cin >> n >> q;
 	ans = (n - 2) * (n - 2);
 	for(int i=0;i<4*MAXN;i++) lazy[i] = lazy2[i] = 1e18;
 	for(int i=0;i<n;i++) a[i] = b[i] = n - 2;
 	build(0, 0, n - 1);
 	build2(0, 0, n - 1);
 	while(q--)
 	{
 		ll type, x;
 		cin >> type;
 		if(type == 1)
 		{
 			cin >> x;
 			x -= 1;
 			ll m = query2(0, 0, n - 1, x, x);
 			ans -= m;
 			range_update(0, 0, n - 1, 1, m, x - 1);
 		}
 		else
 		{
 			cin >> x;
 			x -= 1;
 			ll m = query(0, 0, n - 1, x, x);
 			ans -= m;
 			range_update2(0, 0, n - 1, 1, m, x - 1);
 		}
 	}
 	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27464