#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr char newl = '\n';

// [Related]: monoid_op
// 参考: http://kazuma8128.hatenablog.com/entry/2017/12/29/081929
template <class MonoidOp>
struct LazySegmentTree {
    using Tm = typename MonoidOp::Tm;
    using To = typename MonoidOp::To;

    int n;
    int h;
    vector<Tm> data;
    vector<To> lazy;

    LazySegmentTree() {}

    LazySegmentTree(int size, Tm initial_data_value = MonoidOp::unit()) {
        n = 1;
        h = 0;
        while (n < size) {
            h++;
            n <<= 1;
        }

        data.assign((n << 1), initial_data_value);
        lazy.assign((n << 1), MonoidOp::op_unit());

        if (initial_data_value != MonoidOp::unit()) {
            for (int i = n - 1; i > 0; i--) data[i] = MonoidOp::merge(data[(i << 1)], data[(i << 1) + 1]);
        }
    }

    LazySegmentTree(const vector<Tm>& v) {
        int size = v.size();
        n = 1;
        h = 0;
        while (n < size) {
            h++;
            n <<= 1;
        }

        data.assign((n << 1), MonoidOp::unit());
        lazy.assign((n << 1), MonoidOp::op_unit());

        for (int i = 0; i < size; i++) data[i + n] = v[i];
        for (int i = n - 1; i > 0; i--) data[i] = MonoidOp::merge(data[(i << 1)], data[(i << 1) + 1]);
    }

    // https://komiyam.hatenadiary.org/entry/20131202/1385992406
    inline int getSegLen(int k) {
        return n / (1 << (31 - __builtin_clz(k)));
    }

    Tm getLeaf(int k) {
        return query(k, k + 1);
    }

    void push(int k) {
        if (lazy[k] == MonoidOp::op_unit()) return;
        int seg_len = getSegLen(k);
        data[k] = MonoidOp::apply(data[k], lazy[k], seg_len);
        if (seg_len > 1) {
            lazy[(k << 1)] = MonoidOp::op_merge(lazy[(k << 1)], lazy[k]);
            lazy[(k << 1) + 1] = MonoidOp::op_merge(lazy[(k << 1) + 1], lazy[k]);
        }
        lazy[k] = MonoidOp::op_unit();
    }

    void update(int k) {
        Tm vl = MonoidOp::apply(data[(k << 1)], lazy[(k << 1)], getSegLen(k << 1));
        Tm vr = MonoidOp::apply(data[(k << 1) + 1], lazy[(k << 1) + 1], getSegLen((k << 1) + 1));
        data[k] = MonoidOp::merge(vl, vr);
    }

    //区間[a, b)に対する更新
    void update(int a, int b, To x) {
        a += n, b += n - 1;
        for (int i = h; i > 0; i--) {
            push(a >> i);
            push(b >> i);
        }

        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) lazy[l] = MonoidOp::op_merge(lazy[l], x), l++;
            if (r & 1) --r, lazy[r] = MonoidOp::op_merge(lazy[r], x);
        }

        while (a >>= 1, b >>= 1, a) {
            if (lazy[a] == MonoidOp::op_unit()) update(a);
            if (lazy[b] == MonoidOp::op_unit()) update(b);
        }
    }

    //区間[a, b)に対するクエリに答える
    Tm query(int a, int b) {
        a += n, b += n - 1;
        for (int i = h; i > 0; i--) {
            push(a >> i);
            push(b >> i);
        }

        Tm vl = MonoidOp::unit(), vr = MonoidOp::unit();
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) {
                vl = MonoidOp::merge(vl, MonoidOp::apply(data[l], lazy[l], getSegLen(l)));
                l++;
            }

            if (r & 1) {
                --r;
                vr = MonoidOp::merge(MonoidOp::apply(data[r], lazy[r], getSegLen(r)), vr);
            }
        }
        return MonoidOp::merge(vl, vr);
    }
};

// Tmが非算術型（ex. pair）のときの numeric_limits<Tm>::max() は Tm() なので注意
template<class U = ll, class V = U>
struct RangeMinUpdate {
    using Tm = U;
    using To = V;
    static Tm merge(const Tm& x, const Tm& y) { return min(x, y); }
    static To op_merge(const To& x, const To& y) { return y; }
    static Tm apply(const Tm& vm, const To& vo, int seg_len) { return vo == op_unit() ? vm : vo; }
    static constexpr Tm unit() { return numeric_limits<Tm>::max(); }
    static constexpr To op_unit() { return numeric_limits<To>::max(); }
};

struct Blacks {
    int h_top;
    int w_top;
    int h_bottom;
    int w_bottom;
    Blacks() {}
    Blacks(int ht, int wt, int hb, int wb) : h_top(ht), w_top(wt), h_bottom(hb), w_bottom(wb) {}
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, q;
    cin >> n >> q;

    LazySegmentTree< RangeMinUpdate<int> > hs(vector<int>(n - 2, 0)), ws(vector<int>(n - 2, 0));
    vector<Blacks> blacks;
    blacks.emplace_back(0, 0, n - 3, n - 3);

    int next_id = 1;
    for (int loop = 0; loop < q; loop++) {
        int com, x;
        cin >> com >> x;
        x -= 2;
        if (com == 1) {
            int tar = ws.query(x, x + 1);
            if (tar < 0 || tar >= blacks.size()) continue;
            if (blacks[tar].w_top > blacks[tar].w_bottom || blacks[tar].h_top > blacks[tar].h_bottom) continue;
            assert(blacks[tar].w_top <= x && x <= blacks[tar].w_bottom);

            if (x + 1 <= blacks[tar].w_bottom) {
                blacks.emplace_back(blacks[tar].h_top, x + 1, blacks[tar].h_bottom, blacks[tar].w_bottom);
                ws.update(x, x + 1, -1);
                ws.update(x + 1, blacks[tar].w_bottom + 1, next_id++);
            } else {
                ws.update(x, blacks[tar].w_bottom + 1, -1);
            }
            blacks[tar].w_bottom = x - 1;
            // cerr << blacks[tar].h_top << " " << blacks[tar].w_top << " " << blacks[tar].h_bottom << " " << blacks[tar].w_bottom << newl;
            // cerr << blacks.back().h_top << " " << blacks.back().w_top << " " << blacks.back().h_bottom << " " << blacks.back().w_bottom << newl;
        } else {
            int tar = hs.query(x, x + 1);
            if (tar < 0 || tar >= blacks.size()) continue;
            if (blacks[tar].w_top > blacks[tar].w_bottom || blacks[tar].h_top > blacks[tar].h_bottom) continue;
            assert(blacks[tar].h_top <= x && x <= blacks[tar].h_bottom);

            if (x + 1 <= blacks[tar].h_bottom) {
                blacks.emplace_back(x + 1, blacks[tar].w_top, blacks[tar].h_bottom, blacks[tar].w_bottom);
                hs.update(x, x + 1, -1);
                hs.update(x + 1, blacks[tar].h_bottom + 1, next_id++);
            } else {
                hs.update(x, blacks[tar].h_bottom + 1, -1);
            }
            blacks[tar].h_bottom = x - 1;
            // cerr << blacks[tar].h_top << " " << blacks[tar].w_top << " " << blacks[tar].h_bottom << " " << blacks[tar].w_bottom << newl;
            // cerr << blacks.back().h_top << " " << blacks.back().w_top << " " << blacks.back().h_bottom << " " << blacks.back().w_bottom << newl;
        }
    }

    ll ans = 0;
    for (Blacks& b : blacks) {
        ll hnum = max(b.h_bottom - b.h_top + 1, 0);
        ll wnum = max(b.w_bottom - b.w_top + 1, 0);
        ans += hnum * wnum;
    }
    cout << ans << newl;
    return 0;
}

Measured memory_bytes: 16460