//#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint998244353;
//using mint = modint1000000007;
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//using i128 = __int128_t;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
constexpr char ln = '\n';
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
inline int kthbit(long long x, int k) {return (x>>k)&1;}
inline void print() {cout << "\n";}
template<class T>
inline void print(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cout << *itr << " ";
    print();
}
template<class T, class... Args>
inline void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
#ifdef MINATO_LOCAL
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
inline void debug() {cerr << endl;}
template<class T>
inline void debug(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cerr << *itr << " ";
    debug();
}
template<class T, class... Args>
inline void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
#else
#define dump(x) void(0)
inline void debug() {}
template<class T> inline void debug(const vector<T> &v) {}
template<class T, class... Args> inline void debug(const T &x, const Args &... args) {}
#endif
struct Fast_ios {Fast_ios() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);};} fast_ios;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

template<typename T, typename U, typename F, typename G, typename H>
struct LazySegmentTree {
    F f;
    G g;
    H h;
    T unitynode;
    U unitylazy;
    int N,height;
    vector<T> node;
    vector<U> lazy;
 
    LazySegmentTree() {}
    LazySegmentTree(F f, G g, H h, T unitynode, U unitylazy) : f(f), g(g), h(h), unitynode(unitynode), unitylazy(unitylazy) {}
 
    void init(int sz) {
        N = 1;
        height = 0;
        while (N < sz) {
            N <<= 1;
            ++height;
        }
        node.assign(2*N,unitynode);
        lazy.assign(2*N,unitylazy);
    }
 
    void set(int k, const T &val) {node[k+N] = val;}
 
    void build() {
        for (int i = N-1; i > 0; --i) {
            node[i] = f(node[i<<1|0],node[i<<1|1]);
        }
    }
 
    inline T reflect(int k) {
        return lazy[k] == unitylazy ? node[k] : g(node[k],lazy[k]);
    }
 
    void eval(int k) {
        if (lazy[k] == unitylazy) return;
        if (k < N) {
            lazy[k<<1|0] = h(lazy[k<<1|0],lazy[k]);
            lazy[k<<1|1] = h(lazy[k<<1|1],lazy[k]);
        }
        node[k] = reflect(k);
        lazy[k] = unitylazy;
    }
 
    inline void recalc(int k) {
        while (k >>= 1) {
            node[k] = f(reflect(k<<1|0),reflect(k<<1|1));
        }
    }
 
    // [l,r) (0-indexed)
    void update(int l, int r, U val) {
        if (l >= r) return;
        l += N; r += N-1;
        for (int i = height; i > 0; --i) {
            eval(l>>i);
            eval(r>>i);
        }
        int a = l; int b = r++;
        while (l < r) {
            if (l & 1) lazy[l] = h(lazy[l],val), ++l;
            if (r & 1) --r, lazy[r] = h(lazy[r],val);
            l >>= 1; r >>= 1;
        }
        recalc(a);
        recalc(b);
    }
 
    T get(int l, int r) {
        if (l >= r) return unitynode;
        l += N; r += N-1;
        for (int i = height; i > 0; --i) {
            eval(l>>i);
            eval(r>>i);
        }
        ++r;
        T vl = unitynode, vr = unitynode;
        while (l < r) {
            if (l & 1) vl = f(vl,reflect(l++));
            if (r & 1) vr = f(reflect(--r),vr);
            l >>= 1; r >>= 1;
        }
        return f(vl,vr);
    }
 
    template<typename C>
    int binarysearch(int s, C &check, T &acc, int k, int l, int r) {
        if(r-l==1) {
            acc = f(acc,reflect(k));
            return check(acc) ? k-N : -1;
        }
        eval(k);
        int m = (l+r)>>1;
        if(m <= s) return binarysearch(s, check, acc, (k<<1)|1, m, r);
        if(s <= l && !check(f(acc,node[k]))){
            acc = f(acc,node[k]);
            return -1;
        }
        int vl = binarysearch(s, check, acc, (k<<1)|0, l, m);
        if(~vl) return vl;
        return binarysearch(s, check, acc, (k<<1)|1, m, r);
    }
 
    template<typename C>
    int binarysearch(int s ,C &check) {
        T acc = unitynode;
        return binarysearch(s,check,acc,1,0,N);
    }
};

int main() {
    ll N,Q; cin >> N >> Q;
    auto f=[](ll a, ll b) {return min(a,b);};
    auto g=[](ll a, ll val) {return val;};
    auto h=[](ll a, ll b) {return b;};
    const ll e = 1e18;
    const ll id = -1;
    //vector<ll> RR(N-2,N-2), CC(N-2,N-2);
    LazySegmentTree R(f,g,h,e,id), C(f,g,h,e,id);
    R.init(N-2);
    C.init(N-2);
    rep(i,N-2) R.set(i,N-2);
    rep(i,N-2) C.set(i,N-2);
    R.build();
    C.build();

    ll ans = (N-2)*(N-2);
    int r = N-1, c = N-1;
    while (Q--) {
        int t,x; cin >> t >> x;
        x -= 2;
        if (t==1) {
            int val = R.get(x,x+1);
            dump(x);
            dump(val);
            ans -= val;
            if (chmin(r,x)) {
                C.update(0,val,r);
            }
        } else {
            int val = C.get(x,x+1);
            dump(x);
            dump(val);
            ans -= val;
            if (chmin(c,x)) {
                R.update(0,val,c);
            }
        }
    }

    cout << ans << ln;
}


Measured memory_bytes: 19556