#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

template<class T> 
ostream& operator<<(ostream &os, vector<T> input) {
    os << "[ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "]";
}

template<class T> 
ostream& operator<<(ostream &os, set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, unordered_map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

#define ll long long
const int MAXN = 100005;
const int INF = 1e9;
const int MOD = 1e9 + 7;

class TaskF {
private:

public:
	void solveOne(int it){
		int n, q;
		cin >> n >> q;
		ll ans = (ll)(n-2) * (n-2);
		set<pair<int,int>> sUp, sLeft;
		map<pair<int,int>, int> mpUp, mpLeft;
		sUp.insert(make_pair(1, n));
		mpUp[make_pair(1, n)] = n;
		sLeft.insert(make_pair(1, n));
		mpLeft[make_pair(1, n)] = n;
		while(q--) {
			int ty, x;
			cin >> ty >> x;
			if(ty == 1) {
				auto it = sUp.upper_bound(make_pair(x,n+5));
				assert(it!=sUp.begin());
				it--;
				int lim = mpUp[*it];
				ans -= lim - 2;
				// [1, lim] -> x
				auto it2 = sLeft.begin();
				int from = (*it2).first;
				int to = (*it2).second;
				int mini = mpLeft[*it2];
				if(x < mini) {
					sLeft.erase(it2);
					sLeft.insert(make_pair(1, lim));
					mpLeft[make_pair(1, lim)] = x;
					if(lim+1 <= to) {
						sLeft.insert(make_pair(lim+1, to));
						mpLeft[make_pair(lim+1, to)] = mini;
					}
				}	
			} else {
				auto it = sLeft.upper_bound(make_pair(x,n+5));
				assert(it!=sLeft.begin());
				it--;
				int lim = mpLeft[*it];
				ans -= lim - 2;
				// [1, lim] -> x
				auto it2 = sUp.begin();
				int from = (*it2).first;
				int to = (*it2).second;
				int mini = mpUp[*it2];
				if(x < mini) {
					sUp.erase(it2);
					sUp.insert(make_pair(1, lim));
					mpUp[make_pair(1, lim)] = x;
					if(lim+1 <= to) {
						sUp.insert(make_pair(lim+1, to));
						mpUp[make_pair(lim+1, to)] = mini;
					}
				}	
			
			}
		}
		cout << ans << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	srand(time(NULL));
	ios_base::sync_with_stdio(false);
	TaskF solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 20760