#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string.h>
#include <set>
#include <math.h>
#include <numeric>
#include <assert.h>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <queue>
#include <random>
#include <chrono>
#include <limits.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define endl "\n"
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> OST;
typedef tree<pair<int, int>, null_type, less_equal<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> OST_multiset;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const ll inf = 1e9 + 69;
const ld pi = 3.14159265358979323L;
const ld eps = 1e-15;

void setIn(string s){freopen(s.c_str(), "r", stdin);}
void setOut(string s){freopen(s.c_str(), "w", stdout);}
void unsyncIO(){cin.tie(0) -> sync_with_stdio(0);}
int setIO_count = 0;
void setIO(string s = ""){
	if(!setIO_count){
		unsyncIO();
		setIO_count = 1;
	}
	if(s.size()){ //output only
		setIn(s + ".in");
		setOut(s + ".out");
	}
}

#define gc getchar//_unlocked //can't for window server
#define pc putchar//_unlocked //can't for window server
ll inp(){
	char c = gc(); bool neg = false;
	for(; c < '0'||'9' < c; c = gc())
		if(c == '-') neg=true;
	ll rs = c - '0'; c = gc();
	for(; '0' <= c && c <= '9'; c = gc())
		rs = (rs << 1) + (rs << 3) + (c - '0');
	if(neg) rs = -rs;
	return rs;
}
void pri(ll _n){
	ll N = _n, rev, count = 0;
	bool neg = false;
	if(N < 0){
		N = -N; neg = true;
	}
	rev = N;
	if(N == 0) {pc('0'); return;}
	if(neg) pc('-');
	while(rev % 10 == 0) {count ++; rev /= 10;}
	rev = 0;
	while(N != 0) {rev = (rev << 3) + (rev << 1) + N % 10; N /= 10;}
	while(rev != 0) {pc(rev % 10 + '0'); rev /= 10;}
	while(count --) pc('0');
}

const ll mod = 998244353;
const int N = 2 * 100 * 1000 + 5;

int n, q;
ll st[N * 4][2], lz[N * 4][2];

void build(int nd, int cl, int cr){
	st[nd][0] = st[nd][1] = n - 2;
	lz[nd][0] = lz[nd][1] = inf;

	if(cl == cr) return;
	build(nd * 2, cl, (cl + cr) / 2);
	build(nd * 2 + 1, (cl + cr) / 2 + 1, cr);
}

void prop(int nd, int cl, int cr, int tp){
	if(lz[nd][tp] != inf){
		st[nd][tp] = min(st[nd][tp], lz[nd][tp]);
		if(cl != cr){
			lz[nd * 2][tp] = min(lz[nd * 2][tp], lz[nd][tp]);
			lz[nd * 2 + 1][tp] = min(lz[nd * 2 + 1][tp], lz[nd][tp]);
		}
		lz[nd][tp] = inf;
	}
}

void upd(int nd, int cl, int cr, int l, int r, ll v, int tp){
	prop(nd, cl, cr, tp);
	if(cr < l || r < cl) return;
	if(l <= cl && cr <= r){
		lz[nd][tp] = min(lz[nd][tp], v);
		prop(nd, cl, cr, tp);
		return;
	}

	upd(nd * 2, cl, (cl + cr) / 2, l, r, v, tp);
	upd(nd * 2 + 1, (cl + cr) / 2 + 1, cr, l, r, v, tp);
	st[nd][tp] = min(st[nd * 2][tp], st[nd * 2 + 1][tp]);
}

ll que(int nd, int cl, int cr, int l, int r, int tp){
	prop(nd, cl, cr, tp);
	if(cr < l || r < cl) return inf;
	if(l <= cl && cr <= r) return st[nd][tp];

	return min(que(nd * 2, cl, (cl + cr) / 2, l, r, tp), que(nd * 2 + 1, (cl + cr) / 2 + 1, cr, l, r, tp));
}

int main(){
	setIO("");

	cin >> n >> q;
	build(1, 2, n - 1);

	ll ans = (n - 2) * 1ll * (n - 2);

	for(int tp, x; q --;){
		cin >> tp >> x;
		tp --;

		// for(int i = 2; i <= n - 1; i ++)
		// 	cout << que(1, 2, n - 1, i, i, 0) << " "; cout << endl;
		// for(int i = 2; i <= n - 1; i ++)
		// 	cout << que(1, 2, n - 1, i, i, 1) << " "; cout << endl;
		// cout << endl;
		
		ll ht = que(1, 2, n - 1, x, x, tp);
		ans -= ht;
		upd(1, 2, n - 1, x, x, 0, tp);
		upd(1, 2, n - 1, 2, ht + 1, x - 2, 1 - tp);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 20012