#ifdef MAIN ================================================================================================================================

+library{ name:beats_notmine }

lint x[202020],y[202020];

int solve(){ // prediction failed
	lin(n,q);
	rep(n)x[i]=y[i]=n-2;
	SegmentTree bx(n,x),by(n,y);
	lint ans=(n-2)*(n-2);
	while(q--){
		lin(t,x);--x;
		if(t==1){
			lint qq=bx.query_sum(x,x+1);
			ans-=qq;
			by.update_min(1,qq+1,x-1);
			deb(qq);
		}
		else{
			lint qq=by.query_sum(x,x+1);
			ans-=qq;
			bx.update_min(1,qq+1,x-1);
			deb(qq);

		}
	}
	out(ans);
	return 0;
}

#endif MAIN ================================================================================================================================

//sub-BOF

// desktop
// author: Tqk

// #define _AOJ_
#define _C_INPUT_

// #pragma region template

// #pragma region basic
#define IN_FILE "./in.txt"
//#pragma GCC optimize ("O3")
#pragma warning(disable: 4455 4244 4067 4068 4996)
#pragma GCC target ("avx")
#pragma GCC diagnostic ignored "-Wliteral-suffix"
#define NOMINMAX
#ifdef _ENV_TQK_
#include <Windows.h>
#endif
#include "bits/stdc++.h"
using namespace std;
typedef int64_t lint;
typedef long double ld;
typedef string cs;
#define linf 1152921504606846976
#ifndef _AOJ_
inline lint operator""z(const unsigned long long n){ return lint(n); }
#endif
template<class T>inline T operator-(const vector<T>& a,const size_t&i){return a.at(i);}
// #pragma endregion

// #pragma region rep
#define _vcppunko3(tuple) _getname3 tuple
#define _vcppunko4(tuple) _getname4 tuple
#define _getname4(_1,_2,_3,_4,name,...) name
#define _getname3(_1,_2,_3,name,...) name
#define _trep2(tuple) _rep2 tuple
#define _trep3(tuple) _rep3 tuple
#define _trep4(tuple) _rep4 tuple
#define _rep1(n) for(lint i=0;i<n;++i)
#define _rep2(i,n) for(lint i=0;i<n;++i)
#define _rep3(i,a,b) for(lint i=a;i<b;++i)
#define _rep4(i,a,b,c) for(lint i=a;i<b;i+=c)
#define _tper2(tuple) _per2 tuple
#define _tper3(tuple) _per3 tuple
#define _tper4(tuple) _per4 tuple
#define _per1(n) for(lint i=n-1;i>=0;--i)
#define _per2(i,n) for(lint i=n-1;i>=0;--i)
#define _per3(i,a,b) for(lint i=b-1;i>=a;--i)
#define _per4(i,a,b,c) for(lint i=a+(b-a-1)/c*c;i>=a;i-=c)
#define rep(...) _vcppunko4((__VA_ARGS__,_trep4,_trep3,_trep2,_rep1))((__VA_ARGS__))
#define per(...) _vcppunko4((__VA_ARGS__,_tper4,_tper3,_tper2,_per1))((__VA_ARGS__))
#define _tall2(tuple) _all2 tuple
#define _tall3(tuple) _all3 tuple
#define _all1(v) v.begin(),v.end()
#define _all2(v,a) v.begin(),v.begin()+a
#define _all3(v,a,b) v.begin()+a,v.begin+b
#define all(...) _vcppunko3((__VA_ARGS__,_tall3,_tall2,_all1))((__VA_ARGS__))
#define each(c) for(auto &e:c)
// #pragma endregion

// #pragma region io
template<class T>
istream& operator>>(istream& is,vector<T>& vec);
template<class T,size_t size>
istream& operator>>(istream& is,array<T,size>& vec);
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p);
template<class T>
ostream& operator<<(ostream& os,vector<T>& vec);
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p);
template<class T>
istream& operator>>(istream& is,vector<T>& vec){ for(T& x: vec) is>>x;return is; }
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p){ is>>p.first;is>>p.second;return is; }
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p){ os<<p.first<<" "<<p.second;return os; }
template<class T>
ostream& operator<<(ostream& os,vector<T>& vec){ os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; }
template<class T>
ostream& operator<<(ostream& os,deque<T>& deq){ os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; }
template<class T>
ostream& operator<<(ostream& os,set<T>& s){ each(s)os<<e<<" ";return os; }

#ifdef _ENV_TQK_
/*
ifstream infile(IN_FILE);
template<class T>
ifstream& operator>>(ifstream& is,vector<T>& vec);
template<class T,size_t size>
ifstream& operator>>(ifstream& is,array<T,size>& vec);
template<class T,class L>
ifstream& operator>>(ifstream& is,pair<T,L>& p);
template<class T>
ifstream& operator>>(ifstream& is,vector<T>& vec){ for(T& x: vec) is>>x;return is; }
template<class T,class L>
ifstream& operator>>(ifstream& is,pair<T,L>& p){ is>>p.first;is>>p.second;return is; }
inline void fin(){}
template <class Head,class... Tail>
inline void fin(Head&& head,Tail&&... tail){ infile>>head;fin(move(tail)...); }
*/
//#include<Windows.h>
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
inline void in(){ SetConsoleTextAttribute(hConsole,10); }
template <class Head,class... Tail>
inline void in(Head&& head,Tail&&... tail){
	SetConsoleTextAttribute(hConsole,15);
	cin>>head;in(move(tail)...);
}
#else
inline void in(){}
template <class Head,class... Tail>
inline void in(Head&& head,Tail&&... tail){ cin>>head;in(move(tail)...); }
#endif

inline bool out(){ return(cout<<'\n',0); }
template <class T>
inline bool out(T t){ return(cout<<t<<'\n',0); }
template <class Head,class... Tail>
inline bool out(Head head,Tail... tail){ cout<<head<<' ';out(move(tail)...);return 0; }
template <class T>
inline void alloc(T &c,lint s){ rep(c.size())c[i].resize(s); }
#define alc alloc
#ifdef _ENV_TQK_
inline bool deb(){ SetConsoleTextAttribute(hConsole,10); return(cout<<'\n',0); }
template <class T>
inline bool deb(T t){ return(SetConsoleTextAttribute(hConsole,12),cout<<t<<'\n',SetConsoleTextAttribute(hConsole,10),0); }
template <class Head,class... Tail>
inline bool deb(Head head,Tail... tail){
	SetConsoleTextAttribute(hConsole,12);
	cout<<head<<' ';deb(move(tail)...);return 0;
}
#define dsp(ex) sp(ex)
#define dno(ex) no(ex)
#define look(v) SetConsoleTextAttribute(hConsole,12),cout<<#v<<": ",deb(v);
#else
#define deb(...) 0
#define dsp(ex) 0
#define dno(ex) 0
#define look(v) 0
#endif

// #pragma endregion

// #pragma region TA
#define lin(...) lint __VA_ARGS__;in(__VA_ARGS__)
#define stin(...) string __VA_ARGS__;in(__VA_ARGS__)
#define vin(type,name,size) vector<type> name(size);in(name)
#define pb push_back
#define fi e.first
#define se e.second
#define YES(c) cout<<((c)?"YES\n":"NO\n"),0
#define Yes(c) cout<<((c)?"Yes\n":"No\n"),0
#define POSSIBLE(c) cout<<((c)?"POSSIBLE\n":"IMPOSSIBLE\n"),0
#define Possible(c) cout<<((c)?"Possible\n":"Impossible\n"),0
#define o(p) cout<<p<<endl,0
#define sp(p) cout<<p<<" ",0
#define no(p) cout<<p,0
#define st(v) sort(all(v))
#define psort(l,r) if(l>r)swap(l,r);
#define fn(ty1,ty2,ex) [&](ty1 l,ty2 r){ return(ex); }
#define lfn(ex) [&](lint l,lint r){ return(ex); }

// #pragma endregion

// #pragma region func
inline constexpr lint gcd(lint a,lint b){ while(b){ lint c=b;b=a%b;a=c; }return a; }
inline constexpr lint lcm(lint a,lint b){ return a/gcd(a,b)*b; }
template<typename T>
inline constexpr bool chmin(T &mn,const T &cnt){ if(mn>cnt){ mn=cnt;return 1; } else return 0; }
template<typename T>
inline constexpr bool chmax(T &mx,const T &cnt){ if(mx<cnt){ mx=cnt;return 1; } else return 0; }
// #pragma endregion

// #pragma region P

class P{ public:lint f,s; P(lint a,lint b):f(a),s(b){}; P():f(0),s(0){}; };
istream& operator>>(istream& os,P& p){ os>>p.f>>p.s;return os; }
inline constexpr bool operator<(const P& l,const P& r){ return(l.f-r.f?l.f<r.f:l.s<r.s); }
inline constexpr bool operator>(const P& l,const P& r){ return(l.f-r.f?l.f>r.f:l.s>r.s); }
inline constexpr bool operator==(const P& l,const P& r){ return(l.f==r.f&&l.s==r.s); }
inline constexpr bool operator!=(const P& l,const P& r){ return(l.f!=r.f||l.s!=r.s); }
inline P operator+(const P& l,const P& r){return P(l.f+r.f,l.s+r.s);}
inline P operator-(const P& l,const P& r){return P(l.f-r.f,l.s-r.s);}
inline P operator-(const P& r){return P(-r.f,-r.s); }
inline P operator*(const lint& l,const P& r){return P(l*r.f,l*r.s); }
inline P operator/(const P& l,const lint& r){return P(l.f/r,l.s/r); }
inline ld abs(P p){return sqrtl(p.f*p.f+p.s*p.s);}
inline ld mabs(P p){return abs(p.f)+abs(p.s);}
inline ld mht(P x,P y){return mabs(x-y);}

// #pragma endregion

// #pragma region start
struct Start{
	Start(){
#ifndef _C_INPUT_
		cin.tie(0),cout.tie(0);
		ios::sync_with_stdio(0);
#endif
		cout<<fixed<<setprecision(16);
	}
} __start;
// #pragma endregion

// #pragma endregion

// #pragma region const
#define mod 1000000007
const ld pi=acos(-1);
const ld tau=(1.+sqrtl(5))/2.;
P d4[4]={P(1,0),P(0,1),P(-1,0),P(0,-1)};
P d8[8]={P(1,0),P(1,1),P(0,1),P(-1,1),P(-1,0),P(-1,-1),P(0,-1),P(1,-1)};
const cs AUTO_YES = "Yes";
const cs AUTO_NO = "No";
int cho(bool c,cs yes=AUTO_YES,cs no=AUTO_NO){
	return out((c?yes:no));
}
// #pragma endregion

// #pragma region solve

// #pragma region lib_beats_notmine

// Segment Tree Beats
// - l<=i<r 縺ｫ縺､縺・※縲・A_i 縺ｮ蛟､繧・min(A_i, x) 縺ｫ譖ｴ譁ｰ
// - l<=i<r 縺ｫ縺､縺・※縲・A_i 縺ｮ蛟､繧・max(A_i, x) 縺ｫ譖ｴ譁ｰ
// - l<=i<r 縺ｮ荳ｭ縺ｮ A_i 縺ｮ譛螟ｧ蛟､繧呈ｱゅａ繧・
// - l<=i<r 縺ｮ荳ｭ縺ｮ A_i 縺ｮ譛蟆丞､繧呈ｱゅａ繧・
// - l<=i<r 縺ｮ A_i 縺ｮ蜥後ｒ豎ゅａ繧・
// - l<=i<r 縺ｫ縺､縺・※縲・A_i 縺ｮ蛟､縺ｫ x 繧貞刈縺医ｋ
// - l<=i<r 縺ｫ縺､縺・※縲・A_i 縺ｮ蛟､繧・x 縺ｫ譖ｴ譁ｰ

// 蜷・ヮ繝ｼ繝峨＃縺ｨ縺ｫ讒矩菴薙↓縺ｾ縺ｨ繧√ｋ蠖｢縺ｧ螳溯｣・(縺薙・繧医≧縺ｫ螳溯｣・＠縺ｪ縺・→TLE縺励◆)
class SegmentTree {
	static const lint inf = 1e18;
	struct Node {
		Node* left,* right;
		lint max_v,smax_v,max_c;
		lint min_v,smin_v,min_c;
		lint sum;
		lint len,ladd,lval;

		Node(): left(0),right(0),ladd(0),lval(inf) {}

		void init(lint x) {
			max_v = min_v = sum = x;
			smax_v = -inf; smin_v = inf;
			max_c = min_c = 1;
		}

		void init_empty() {
			max_v = smax_v = -inf;
			min_v = smin_v = inf;
			max_c = min_c = 0;
		}

		void update_max(lint x) {
			sum += (x - max_v) * max_c;

			if(max_v == min_v) {
				max_v = min_v = x;
			}
			else if(max_v == smin_v) {
				max_v = smin_v = x;
			}
			else {
				max_v = x;
			}

			if(lval != inf && x < lval) {
				lval = x;
			}
		}

		void update_min(lint x) {
			sum += (x - min_v) * min_c;

			if(max_v == min_v) {
				max_v = min_v = x;
			}
			else if(max_v == smin_v) {
				min_v = smax_v = x;
			}
			else {
				min_v = x;
			}

			if(lval != inf && lval < x) {
				lval = x;
			}
		}

		void addalint(lint x) {
			max_v += x;
			if(smax_v != -inf) smax_v += x;
			min_v += x;
			if(smin_v != inf) smin_v += x;

			sum += len * x;
			if(lval != inf) {
				lval += x;
			}
			else {
				ladd += x;
			}
		}

		void updatealint(lint x) {
			max_v = min_v = x;
			smax_v = -inf; smin_v = inf;
			max_c = min_c = len;

			sum = len * x;
			lval = x; ladd = 0;
		}

		void push() {

			if(lval != inf) {
				left->updatealint(lval);
				right->updatealint(lval);
				lval = inf;
				return;
			}

			if(ladd != 0) {
				left->addalint(ladd);
				right->addalint(ladd);
				ladd = 0;
			}

			if(max_v < left->max_v) {
				left->update_max(max_v);
			}
			if(left->min_v < min_v) {
				left->update_min(min_v);
			}

			if(max_v < right->max_v) {
				right->update_max(max_v);
			}
			if(right->min_v < min_v) {
				right->update_min(min_v);
			}
		}

		void update() {
			sum = left->sum + right->sum;

			if(left->max_v < right->max_v) {
				max_v = right->max_v;
				max_c = right->max_c;
				smax_v = max(left->max_v,right->smax_v);
			}
			else if(left->max_v > right->max_v) {
				max_v = left->max_v;
				max_c = left->max_c;
				smax_v = max(left->smax_v,right->max_v);
			}
			else {
				max_v = left->max_v;
				max_c = left->max_c + right->max_c;
				smax_v = max(left->smax_v,right->smax_v);
			}

			if(left->min_v < right->min_v) {
				min_v = left->min_v;
				min_c = left->min_c;
				smin_v = min(left->smin_v,right->min_v);
			}
			else if(left->min_v > right->min_v) {
				min_v = right->min_v;
				min_c = right->min_c;
				smin_v = min(left->min_v,right->smin_v);
			}
			else {
				min_v = left->min_v;
				min_c = left->min_c + right->min_c;
				smin_v = min(left->smin_v,right->smin_v);
			}
		}
	};

	int n,n0;
	Node* root;

	void _update_min(lint x,int a,int b,Node* nd,int l,int r) {
		if(b <= l || r <= a || nd->max_v <= x) {
			return;
		}
		if(a <= l && r <= b && nd->smax_v < x) {
			nd->update_max(x);
			return;
		}

		nd->push();
		_update_min(x,a,b,nd->left,l,(l+r)/2);
		_update_min(x,a,b,nd->right,(l+r)/2,r);
		nd->update();
	}

	void _update_max(lint x,int a,int b,Node* nd,int l,int r) {
		if(b <= l || r <= a || x <= nd->min_v) {
			return;
		}
		if(a <= l && r <= b && x < nd->smin_v) {
			nd->update_min(x);
			return;
		}

		nd->push();
		_update_max(x,a,b,nd->left,l,(l+r)/2);
		_update_max(x,a,b,nd->right,(l+r)/2,r);
		nd->update();
	}

	void _add_val(lint x,int a,int b,Node* nd,int l,int r) {
		if(b <= l || r <= a) {
			return;
		}
		if(a <= l && r <= b) {
			nd->addalint(x);
			return;
		}

		nd->push();
		_add_val(x,a,b,nd->left,l,(l+r)/2);
		_add_val(x,a,b,nd->right,(l+r)/2,r);
		nd->update();
	}

	void _update_val(lint x,int a,int b,Node* nd,int l,int r) {
		if(b <= l || r <= a) {
			return;
		}
		if(a <= l && r <= b) {
			nd->updatealint(x);
			return;
		}

		nd->push();
		_update_val(x,a,b,nd->left,l,(l+r)/2);
		_update_val(x,a,b,nd->right,(l+r)/2,r);
		nd->update();
	}

	lint _query_max(int a,int b,Node* nd,int l,int r) {
		if(b <= l || r <= a) {
			return -inf;
		}
		if(a <= l && r <= b) {
			return nd->max_v;
		}
		nd->push();
		lint lv = _query_max(a,b,nd->left,l,(l+r)/2);
		lint rv = _query_max(a,b,nd->right,(l+r)/2,r);
		return max(lv,rv);
	}

	lint _query_min(int a,int b,Node* nd,int l,int r) {
		if(b <= l || r <= a) {
			return inf;
		}
		if(a <= l && r <= b) {
			return nd->min_v;
		}
		nd->push();
		lint lv = _query_min(a,b,nd->left,l,(l+r)/2);
		lint rv = _query_min(a,b,nd->right,(l+r)/2,r);
		return min(lv,rv);
	}

	lint _query_sum(int a,int b,Node* nd,int l,int r) {
		if(b <= l || r <= a) {
			return 0;
		}
		if(a <= l && r <= b) {
			return nd->sum;
		}
		nd->push();
		lint lv = _query_sum(a,b,nd->left,l,(l+r)/2);
		lint rv = _query_sum(a,b,nd->right,(l+r)/2,r);
		return lv + rv;
	}

public:
	SegmentTree(int n,lint* a): n(n) {
		n0 = 1;
		while(n0 < n) n0 <<= 1;

		Node* nds = new Node[2*n0];
		root = nds;

		nds[0].len = n0;
		for(int i = 0; i<n0-1; ++i) {
			nds[i].left = &nds[2*i+1];
			nds[i].right = &nds[2*i+2];
			nds[2*i+1].len = nds[2*i+2].len = (nds[i].len >> 1);
		}

		for(int i = 0; i<n; ++i) nds[n0-1+i].init(a[i]);
		for(int i = n; i<n0; ++i) nds[n0-1+i].init_empty();
		for(int i = n0-2; i>=0; i--) nds[i].update();
	}

	void update_min(int a,int b,lint x) {
		_update_min(x,a,b,root,0,n0);
	}

	void update_max(int a,int b,lint x) {
		_update_max(x,a,b,root,0,n0);
	}

	void add_val(int a,int b,lint x) {
		_add_val(x,a,b,root,0,n0);
	}

	void update_val(int a,int b,lint x) {
		_update_val(x,a,b,root,0,n0);
	}

	lint query_max(int a,int b) {
		return _query_max(a,b,root,0,n0);
	}

	lint query_min(int a,int b) {
		return _query_min(a,b,root,0,n0);
	}

	lint query_sum(int a,int b) {
		return _query_sum(a,b,root,0,n0);
	}
};

// #pragma endregion

lint x[202020],y[202020];

int solve(){ // prediction failed
	lin(n,q);
	rep(n)x[i]=y[i]=n-2;
	SegmentTree bx(n,x),by(n,y);
	lint ans=(n-2)*(n-2);
	while(q--){
		lin(t,x);--x;
		if(t==1){
			lint qq=bx.query_sum(x,x+1);
			ans-=qq;
			by.update_min(1,qq+1,x-1);
			deb(qq);
		}
		else{
			lint qq=by.query_sum(x,x+1);
			ans-=qq;
			bx.update_min(1,qq+1,x-1);
			deb(qq);

		}
	}
	out(ans);
	return 0;
}

// #pragma endregion

// #pragma region main

int main(){
	solve();
	return 0;
}

// #pragma endregion

//sub-EOF


Measured memory_bytes: 105088