#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,Q;
int main(){
    cin>>N>>Q;
    set<P> st1,st2;
    st1.insert(P(N,N-2));
    st2.insert(P(N,N-2));
    ll top=N,left=N;
    ll ans=(N-2)*(N-2);
    vector<ll> v;
    for(ll i=0;i<Q;i++){
        ll a,x;
        cin>>a>>x;
        set<P>& st=(a==1)?st1:st2;
        ll otherleast=(a==1)?top:left;
        ll val;
        if(st.empty() || x < st.begin()->first){
            val=(otherleast-2);
            ans-=val;
            if(a==1){
                left=x;
            }else{
                top=x;
            }
        }else{
            auto it=st.lower_bound(P(x,0));
            it--;
            val=it->second;
            ans-=val;
        }
        st.insert(P(x,val));
    }
    cout<<ans<<endl;
    return 0;
}