#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const int  N     =  5e5+5;
const int  mod   =  998244353;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const int  LEVEL =  log2(N)+1;

ll n, q;

int tree[4*N+8], lazy[4*N+8];

void build(int node, int start, int end){
	if(start == end){
		tree[node] = n;
	}
	else{
		int mid = (start + end) / 2;
		build(2*node, start, mid);
		build(2*node+1, mid+1, end);
		tree[node] = min(tree[2*node], tree[2*node+1]);
	}
}


void pushlazy(int start, int end, int node){
	if(lazy[node] == n+2) return;
	tree[node] = min(tree[node], lazy[node]);
	if(start != end){
		lazy[node*2] = min(lazy[node*2], lazy[node]);
		lazy[node*2+1] = min(lazy[node*2+1], lazy[node]);
	}
	lazy[node] = n+2;
}

void update(int node, int start, int end, int l, int r, int val){
	pushlazy(start, end, node);
	if(start > end or start > r or end < l)
		return;
	if(start >= l and end <= r){
		lazy[node] = min(lazy[node], val);
		pushlazy(start, end, node);
		return;
	}
	int mid = (start + end) / 2;
	update(node*2, start, mid, l, r, val);
	update(node*2 + 1, mid + 1, end, l, r, val);
	tree[node] = min(tree[2*node],tree[2*node+1]);
}

int query(int node, int start, int end, int l, int r){
	if(start > end or start > r or end < l)
		return INFi;
	pushlazy(start, end, node);
	if(l <= start and end <= r)
		return tree[node];
	int mid = (start + end) / 2;
	int p1 = query(2*node, start, mid, l, r);
	int p2 = query(2*node+1, mid+1, end, l, r);
	return min(p1, p2);
}

void solve(){
	cin >> n >> q;
	ll ans = (n - 2)*(n - 2);
	build(1, 1, 2*n);
	for(int i = 1; i < 4*N + 8; i++) lazy[i] = n+2;
	for(int i = 1; i <= q; i++){
		int y, x; cin >> y >> x;
		if(y == 1){
			int ind = query(1, 1, 2*n, x, x);
			ans -= ind - 2;
			update(1, 1, 2*n, n + 2, n + ind - 1, x);
		} else {
			int ind = query(1, 1, 2*n, n + x, n + x);
			ans -= ind - 2;
			update(1, 1, 2*n, 2, ind - 1, x);
		}
	}
	deb1(ans)
}

int main(){
	GODSPEED;
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

Measured memory_bytes: 15576