//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9; 
const int N = 6e5+5;                                         
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}

int n, q;
ll ans;

struct SegTree {
	int mn[N*4], mx[N*4];
	int add[N*4];
	
	void build (int v = 1, int tl = 1, int tr = n) {
		add[v] = 0;
		mn[v] = mx[v] = n;
		if(tl < tr) {
			int tm = (tl+tr)>>1;
			build(v<<1, tl, tm);
			build(v<<1|1, tm + 1, tr);
		}
	}
	void push(int v, int tl, int tr) {
		if(!add[v])
			return;
		if(tl < tr) {
			add[v<<1] = add[v<<1|1] = add[v];
		}
		
		mn[v] = mx[v] = add[v];
		add[v] = 0;
	}
	
	void upd (int p, int x, int v = 1, int tl = 1, int tr = n) {
		push(v, tl, tr);
			
		if(tl > p || mx[v] <= x)
			return;
		if (tr <= p && mn[v] >= x) {
			add[v] = x;
			push(v, tl, tr);
			return;
		}
		
		int tm = (tl+tr)>>1;
		upd(p, x, v<<1, tl, tm);
		upd(p, x, v<<1|1, tm + 1, tr);
	}
	
	int get (int p, int v = 1, int tl = 1, int tr = n) {
		push(v, tl, tr);
	
		if(tl == tr) {
			assert(mx[v] == mn[v]);
			return mx[v];
		}
		
		int tm = (tl+tr) >> 1;
		if (p <= tm) return get(p, v<<1, tl, tm);
		return get(p, v<<1|1, tm + 1, tr);
	}
} S[2];

int main () {
	SpeedForce;
	
	cin >> n >> q;
	ans = (n-2) * (ll)(n-2);
	for (int it = 0; it < 2; ++it) S[it].build();
	set < pair<int, int> > used;
	for (int i = 1; i <= q; ++i) {
		int op, x;
		cin >> op >> x;
		--op;
		if(used.count({op, x}))
			continue;
		used.insert({op, x});
		int rev = !op;
		
		int cur = S[op].get(x);
		
		ans -= cur - 2;
		S[rev].upd(cur, x);
	}
	cout << ans << '\n';
		
	
	return Accepted;
}

// B...a


Measured memory_bytes: 25308