//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<class T>
struct LazySegTree {
    using OP = function<T(T, T)>;  // function type for operation
    using UP = function<void(T &, T)>; // function type for updater

    OP op;
    UP up_d, up_l;
    T ue_d, ue_l; // unit element for dat and lazy
    int N;
    vector<T> dat, lazy;

    int get_n(int n) {
        int ret = 1;
        while (ret < n) ret <<= 1;

        return ret;
    }

    explicit LazySegTree(int n,
                         // todo : ↓↓↓ edit from here ↓↓↓
                         const OP _op = [](ll a, ll b){return min(a, b);},
                         const UP _up_d = [](ll &d, ll v) { d = min(d, v); },
                         const UP _up_l = [](ll &d, ll v) { d = min(d, v); },
                         const T _ue_d = INF,
                         const T _ue_l = INF)
            : op(_op), up_d(_up_d), up_l(_up_l), ue_d(_ue_d), ue_l(_ue_l) {
        N = get_n(n);
        dat.assign(N * 2 - 1, ue_d);
        lazy.assign(N * 2 - 1, ue_l);
    }

    /* set, a is 0-indexed */
    void init(const T& v) {
        REP(i, N) dat[i + N - 1] = v;
        for(int i = N - 2; i >= 0; --i) {
            dat[i] = op(dat[i*2+1], dat[i*2+2]);
        }
    }

    inline void evaluate(int k) {
        if (lazy[k] == ue_l) return;

        if (k < N - 1) {
            up_l(lazy[k * 2 + 1], lazy[k]);
            up_l(lazy[k * 2 + 2], lazy[k]);
        }

        up_d(dat[k], lazy[k]);
        lazy[k] = ue_l;
    }

    // update [a, b). 0-indexed!!!!!!!!!!!
    void update(int a, int b, const T &v, int k = 0, int l = 0, int r = -1) {
        evaluate(k);
        if (r < 0) r = N;

        if (r <= a || b <= l) return;

        if (a <= l && r <= b) {
            up_l(lazy[k], v);
            evaluate(k);
            return;
        }

        int mid = (l + r) / 2;
        update(a, b, v, k * 2 + 1, l, mid);
        update(a, b, v, k * 2 + 2, mid, r);

        dat[k] = op(dat[k * 2 + 1], dat[k * 2 + 2]);
    }

    // update single position
    void update(int i, const T &v) {
        update(i, i+1, v);
    }

    // query for [a, b). 0-indexed!!!!!!!!!!!
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = N;

        if (r <= a || b <= l) return ue_d;

        evaluate(k);
        if (a <= l && r <= b) return dat[k];

        int mid = (l + r) / 2;
        T q1 = query(a, b, k * 2 + 1, l, mid);
        T q2 = query(a, b, k * 2 + 2, mid, r);

        return op(q1, q2);
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll n, q;
    cin >> n >> q;

    LazySegTree<ll> st_x(n - 2), st_y(n - 2);

    ll ans = (n - 2) * (n - 2);
    REP(i, q) {
        int t, x; cin >> t >> x;
        x--;

        if (t == 1) {
            ll l = st_y.query(x, x+1);
            if (l == INF) l = n - 2;
            ans -= l;
            st_x.update(1, l + 1, x - 1);
        } else {
            ll l = st_x.query(x, x+1);
            if (l == INF) l = n - 2;
            ans -= l;
            st_y.update(1, l + 1, x - 1);
        }
    }
    print(ans);

}


Measured memory_bytes: 19572