/**
 *	author: nok0
 *	created: 2020.09.19 20:45:51
**/
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ll long long
#define ld long double
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(int i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(long double &a) { cin >> a; }
void scan(char a[]) { scanf("%s", a); }
void scan(string &a) { cin >> a; }
template <class T> void scan(V<T> &);
template <class T, class L> void scan(pair<T, L> &);
template <class T> void scan(V<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p){
    is >> p.first >> p.second;
    return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p){
    os << p.first << " " << p.second;
    return os;
}
template <class T>
ostream &operator<<(ostream &os, const V<T> &v){
    REP(i, SZ(v)){
        if(i) os << " ";
        os << v[i];
    }
    return os;
}
//debug
template <typename T>
void view(const V<T> &v){
    cerr << "{ ";
    for(const auto &e : v){
        cerr << e << ", ";
    }
    cerr << "\b\b }";
}
template <typename T>
void view(const VV<T> &vv){
    cerr << "{\n";
    for(const auto &v : vv){
        cerr << "\t";
        view(v);
        cerr << "\n";
    }
    cerr << "}";
}
template <typename T, typename U>
void view(const V<pair<T, U>> &v){
    cerr << "{\n";
    for(const auto &c : v) cerr << "\t(" << c.first << ", " << c.second << ")\n";
    cerr << "}";
}
template <typename T, typename U>
void view(const map<T, U> &m){
    cerr << "{\n";
    for(auto &t : m) cerr << "\t[" << t.first << "] : " << t.second << "\n";
    cerr << "}";
}
template <typename T, typename U>
void view(const pair<T, U> &p){ cerr << "(" << p.first << ", " << p.second << ")";}
template <typename T>
void view(const set<T> &s) {
    cerr << "{ ";
    for(auto &t : s) {
        view(t);
        cerr << ", ";
    }
    cerr << "\b\b }";
}
template <typename T>
void view(T e) { cerr << e;}
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    view(H);
    cerr << ", ";
    debug_out(T...);
}
#define debug(...)                                           \
    do{                                                     \
        cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
        debug_out(__VA_ARGS__);                              \
        cerr << "\b\b]\n";                                   \
    } while(0)
#else
#define debug(...) (void(0))
#endif
template <class T> V<T> press(V<T> &x){ 
    V<T> res = x;
    sort(all(res));
    res.erase(unique(all(res)), res.end());
    REP(i, SZ(x)){
        x[i] = lower_bound(all(res), x[i]) - res.begin();
    }
    return res;
}
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T divup(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
struct iofast{iofast(){ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15);}}iofast_;
const int inf = 1e9;
const ll INF = 1e18;
#pragma endregion
class SegtreeBeats {

    int n, rr;
    vector<ll>mx_v, mn_v, smx_v, smn_v, lz_upd, lz_ad, sigm, len;
    vector<int>mx_c, mn_c;
    const ll mx = 1e18, mn = -1e18;

public:
    SegtreeBeats() {}
    SegtreeBeats(vector<ll>& v) {
        init(v);
    }
    void init(vector<ll>& v) {
        n = v.size();
        rr = 1; while (rr < n) rr *= 2;

        mx_v.assign(2 * rr - 1, mn); mn_v.assign(2 * rr - 1, mx);
        smx_v.assign(2 * rr - 1, mn); smn_v.assign(2 * rr - 1, mx);
        lz_upd.assign(2 * rr - 1, mx); lz_ad.assign(2 * rr - 1, 0);
        len.assign(2 * rr - 1, rr);
        sigm.assign(2 * rr - 1, 0);
        mx_c.assign(2 * rr - 1, 1); mn_c.assign(2 * rr - 1, 1);

        for (int i = 0; i < rr - 1; i++) len[i * 2 + 1] = len[i * 2 + 2] = len[i] >> 1;

        for (int i = 0; i < n; i++) {
            mx_v[i + rr - 1] = mn_v[i + rr - 1] = sigm[i + rr - 1] = v[i];
        }
        for (int i = rr - 2; i >= 0; i--) {
            proc(i);
        }
    }

    void chmin(int a, int b,ll x) {
        chmin(0, a, b, 0, rr,x);
    }
    void chmax(int a, int b,ll x) {
        chmax(0, a, b, 0, rr,x);
    }
    void update(int a, int b,ll x) {
        update(0, a, b, 0, rr, x);
    }
    void add(int a, int b, ll x) {
        add(0, a, b, 0, rr, x);
    }


    ll rangemin(int a, int b) {
        return rangemin(0, a, b, 0, rr);
    }
    ll rangemax(int a, int b) {
        return rangemax(0, a, b, 0, rr);
    }
    ll sum(int a, int b) {
        return sum(0, a, b, 0, rr);
    }

private:
    ll rangemin(int i, int a, int b, int l, int r) {
        if (r <= a || b <= l) return mx;
        if (a <= l && r <= b) return mn_v[i];
        eval(i);
        ll lv = rangemin(i * 2 + 1, a, b, l, (l + r) / 2);
        ll rv = rangemin(i * 2 + 2, a, b, (l + r) / 2,r);
        return min(lv, rv);
    }
    ll rangemax(int i, int a, int b, int l, int r) {
        if (r <= a || b <= l) return mn;
        if (a <= l && r <= b) return mx_v[i];
        eval(i);
        ll lv = rangemax(i * 2 + 1, a, b, l, (l + r) / 2);
        ll rv = rangemax(i * 2 + 2, a, b, (l + r) / 2, r);
        return max(lv, rv);
    }
    ll sum(int i, int a, int b, int l, int r) {
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return sigm[i];
        eval(i);
        ll lv = sum(i * 2 + 1, a, b, l, (l + r) / 2);
        ll rv = sum(i * 2 + 2, a, b, (l + r) / 2, r);
        return lv + rv;
    }

    void chmin(int i, int a, int b, int l, int r, ll x) {
        if (b <= l || r <= a || x >= mx_v[i]) return;

        if (a <= l && r <= b && smx_v[i] < x) {
            in_chmin(i, x);
            return;
        }//ここの値を直す。だけ。

        eval(i);//子供の値も正しくする
        chmin(i * 2 + 1, a, b, l, (l + r) / 2, x);
        chmin(i * 2 + 2, a, b, (l + r) / 2, r, x);
        proc(i);
    }
    void chmax(int i, int a, int b, int l, int r, ll x) {
        if (b <= l || r <= a || x <= mn_v[i]) return;

        if (a <= l && r <= b && smn_v[i] > x) {
            in_chmax(i, x);
            return;
        }//ここの値を直す。だけ。

        eval(i);//子供の値も正しくする
        chmax(i * 2 + 1, a, b, l, (l + r) / 2, x);
        chmax(i * 2 + 2, a, b, (l + r) / 2, r, x);
        proc(i);
    }
    void add(int i, int a, int b, int l, int r, ll x) {
        if (b <= l || r <= a) return;

        if (a <= l && r <= b) {
            in_add(i, x);
            return;
        }//ここの値を直す。だけ。

        eval(i);//子供の値も正しくする
        add(i * 2 + 1, a, b, l, (l + r) / 2, x);
        add(i * 2 + 2, a, b, (l + r) / 2, r, x);
        proc(i);
    }
    void update(int i, int a, int b, int l, int r, ll x) {
        if (b <= l || r <= a) return;

        if (a <= l && r <= b) {
            in_update(i, x);
            return;
        }//ここの値を直す。だけ。

        eval(i);//子供の値も正しくする
        update(i * 2 + 1, a, b, l, (l + r) / 2, x);
        update(i * 2 + 2, a, b, (l + r) / 2, r, x);
        proc(i);
    }

    void eval(int i) {
        //chmin, update, add
        //update->add 組み込む
        //add->chmin やるだけ
        //chmin->add

        if (lz_upd[i] != mx) {
            in_update(i * 2 + 1, lz_upd[i]);
            in_update(i * 2 + 2, lz_upd[i]);
            lz_upd[i] = mx;
            return;
        }//updateされていた場合は、死ぬ

        if (lz_ad[i]) {
            in_add(i * 2 + 1, lz_ad[i]);
            in_add(i * 2 + 2, lz_ad[i]);
            lz_ad[i] = 0;
        }

        if (mx_v[i] < mx_v[i * 2 + 1]) in_chmin(i * 2 + 1, mx_v[i]);
        if (mx_v[i] < mx_v[i * 2 + 2]) in_chmin(i * 2 + 2, mx_v[i]);

        if (mn_v[i] > mn_v[i * 2 + 1]) in_chmax(i * 2 + 1, mn_v[i]);
        if (mn_v[i] > mn_v[i * 2 + 2]) in_chmax(i * 2 + 2, mn_v[i]);
    }//子供に情報を伝搬する

    void proc(int i) {
        sigm[i] = sigm[i * 2 + 1] + sigm[i * 2 + 2];


        mx_v[i] = max(mx_v[i * 2 + 1], mx_v[i * 2 + 2]);
        if (mx_v[i * 2 + 1] > mx_v[i * 2 + 2]) {
            mx_c[i] = mx_c[i * 2 + 1];
            smx_v[i] = max(smx_v[i * 2 + 1], mx_v[i * 2 + 2]);
        }
        else if (mx_v[i * 2 + 1] < mx_v[i * 2 + 2]) {
            mx_c[i] = mx_c[i * 2 + 2];
            smx_v[i] = max(smx_v[i * 2 + 2], mx_v[i * 2 + 1]);
        }
        else {
            mx_c[i] = mx_c[i * 2 + 1] + mx_c[i * 2 + 2];
            smx_v[i] = max(smx_v[i * 2 + 1], smx_v[i * 2 + 2]);
        }


        mn_v[i] = min(mn_v[i * 2 + 1], mn_v[i * 2 + 2]);
        if (mn_v[i * 2 + 1] < mn_v[i * 2 + 2]) {
            mn_c[i] = mn_c[i * 2 + 1];
            smn_v[i] = min(smn_v[i * 2 + 1], mn_v[i * 2 + 2]);
        }
        else if (mn_v[i * 2 + 1] > mn_v[i * 2 + 2]) {
            mn_c[i] = mn_c[i * 2 + 2];
            smn_v[i] = min(smn_v[i * 2 + 2], mn_v[i * 2 + 1]);
        }
        else {
            mn_c[i] = mn_c[i * 2 + 1] + mn_c[i * 2 + 2];
            smn_v[i] = min(smn_v[i * 2 + 1], smn_v[i * 2 + 2]);
        }
    }//子供から値を伝搬する

    void in_update(int i, ll x) {
        mx_v[i] = mn_v[i] = x;
        smx_v[i] = mn; smn_v[i] = mx;
        mx_c[i] = mn_c[i] = len[i];
        sigm[i] = len[i] * x;
        lz_upd[i] = x, lz_ad[i] = 0;
    }
    void in_add(int i, ll x) {
        mx_v[i] += x; mn_v[i] += x;
        if (smn_v[i] != mx) smn_v[i] += x;
        if (smx_v[i] != mn) smx_v[i] += x;
        sigm[i] += x * len[i];

        if (lz_upd[i] != mx)
            lz_upd[i] += x;
        lz_ad[i] += x;
    }
    void in_chmin(int i, ll x) {
        sigm[i] += (x - mx_v[i]) * mx_c[i];

        if (mx_v[i] == mn_v[i])
            mx_v[i] = mn_v[i] = x;
        else if (mx_v[i] == smn_v[i])
            mx_v[i] = smn_v[i] = x;
        else mx_v[i] = x;

        if (lz_upd[i] != mx && lz_upd[i] > x) lz_upd[i] = x;
    }
    void in_chmax(int i, ll x) {
        sigm[i] += (x - mn_v[i]) * mn_c[i];

        if (mn_v[i] == mx_v[i])
            mx_v[i] = mn_v[i] = x;
        else if (mn_v[i] == smx_v[i])
            mn_v[i] = smx_v[i] = x;
        else mn_v[i] = x;

        if (lz_upd[i] != mx && lz_upd[i] < x) lz_upd[i] = x;
    }
};

int main(){
    LL(n, q);
    ll res = (n - 2) * (n - 2);
    V<ll> a(n, n - 1);
    SegtreeBeats Tate(a), Yoko(a);
    while(q--){
        INT(type, x);
        x--;
        if(type == 1){
            int z = Tate.sum(x, x + 1);
            debug(z);
            Yoko.chmin(0, z, x);
            res -= z - 1;
        }
        if(type == 2){
            int z = Yoko.sum(x, x + 1);
            debug(z);
            Tate.chmin(0, z, x);
            res -= z - 1;
        }
        debug(res);
    }
    print(res);
}

Measured memory_bytes: 78712