#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,Q;
    cin >> N >> Q;
    ll ans = (N-2)*(N-2);
    vec<int> valrow(N,-1),valcol(N,-1);
    int r = N-1,c = N-1;
    while(Q--){
        int t,x;
        cin >> t >> x;
        x--;
        if(t==1){
            if(valcol[x]!=-1) ans -= valcol[x];
            else{
                ans -= r-1;
                for(int i=x+1;i<c;i++) valcol[i] = r-1;
                c = x;
            }
        }else{
            if(valrow[x]!=-1) ans -= valrow[x];
            else{
                ans -= c-1;
                for(int i=x+1;i<r;i++) valrow[i] = c-1;
                r = x;
            }
        }
    }
    cout << ans << "\n";
}