#include "bits/stdc++.h"

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

const ll INF = 1e9 + 7;

template<typename T, typename S> struct LazySegmentTree{
    const ll INF = 1e9 + 7;
    int SZ;
    T id;
    vector<T> t;
    vector<S> lazy;
    LazySegmentTree(T x, int sz): id(x), SZ(sz), lazy((SZ << 2) + 5, INF), t((SZ << 2) + 5) {}
    LazySegmentTree(vector<T> &a, T x, int sz): id(x), SZ(sz), lazy((SZ << 2) + 5, INF), t((SZ << 2) + 5){
        build(1, 0, SZ - 1, a);
    }
    void push(int v, int tl, int tr){
        if(lazy[v] == INF) return;
        int tm = tl + (tr - tl)/2;
        if((v << 1) < (SZ << 2) + 5){
            ckmin(lazy[v << 1], lazy[v]);
            ckmin(t[v << 1], lazy[v]);
        }
        if(((v << 1) | 1) < (SZ << 2) + 5){
            ckmin(lazy[(v << 1) | 1], lazy[v]);
            ckmin(t[(v << 1) | 1], lazy[v]);
        }
        lazy[v] = INF;
    }
    T cmb(T x, T y){ return min(x, y);}
    void build(int v, int tl, int tr, vector<T> &a){
        if(tl == tr) t[v] = a[tl];
        else{
            int tm = tl + (tr - tl)/2;
            build(v << 1, tl, tm, a);
            build((v << 1) | 1, tm + 1, tr, a);
            t[v] = cmb(t[v << 1], t[(v << 1) | 1]);
        }
    }
    T qry(int l, int r){ return qry(1, 0, SZ - 1, l, r);};
    T qry(int v, int tl, int tr, int l, int r){
        push(v, tl, tr);
        if(l > r) return id;
        int tm = tl + (tr - tl)/2;
        if(tl == l && tr == r) return t[v];
        return cmb(qry(v << 1, tl, tm, l, min(r, tm)), qry((v << 1) | 1, tm + 1, tr, max(l, tm + 1), r));
    }
    void upd(int l, int r, T x){ upd(1, 0, SZ - 1, l, r, x);};
    void upd(int v, int tl, int tr, int l, int r, T x){
        push(v, tl, tr);
        if(l > r) return;
        int tm = tl + (tr - tl)/2;
        if(tl == l && tr == r){
            //change lazy op based on lazy
            ckmin(lazy[v], x);
            ckmin(t[v], x);
        }
        else{
            upd(v << 1, tl, tm, l, min(r, tm), x);
            upd((v << 1) | 1, tm + 1, tr, max(l, tm + 1), r, x);
            t[v] = cmb(t[v << 1], t[(v << 1) | 1]);
        }
    }
};

ll n, q;
vector<ll> v;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> q;
    v.assign(n, n - 1);
    LazySegmentTree<ll, ll> t1(v, INF, n), t2(v, INF, n);
    ll res = (n - 2) * (n - 2);
    while(q--){
        ll t, x;
        cin >> t >> x; --x;
        if(t == 1){
            ll cur = t1.qry(x, x);
            // cout << cur - 1 << "\n";
            if(cur){
                res -= cur - 1;
                t1.upd(x, x, 0);
                t2.upd(1, cur, x);
            }
        }
        else{
            ll cur = t2.qry(x, x);
            // cout << cur - 1 << "\n";
            if(cur){
                res -= cur - 1;
                t2.upd(x, x, 0);
                t1.upd(1, cur, x);
            }
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 29868