#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

template <typename T>
class LazySegmentTree {
    using fn = function<T(T, T)>;

   public:
    LazySegmentTree(vector<T> &base, fn _fx, fn _fa, fn _fm, T _ex, T _em) : fx(_fx), fa(_fa), fm(_fm), ex(_ex), em(_em) {
        n = 1; while (n < base.size()) n *= 2;

        node.resize(2 * n - 1, ex);
        REP(i, 0, base.size()) node[n - 1 + i] = base[i];
        for (int i = n - 2; i >= 0; i--) node[i] = fx(node[2 * i + 1], node[2 * i + 2]);

        lazy.resize(2 * n - 1, em);
    }

    void eval(int k, int l, int r) {
        if (lazy[k] == em) return;

        if (r - l > 1) {
            lazy[2 * k + 1] = fm(lazy[2 * k + 1], lazy[k]);
            lazy[2 * k + 2] = fm(lazy[2 * k + 2], lazy[k]);
        }
        node[k] = fa(node[k], lazy[k]);
        lazy[k] = em;
    }

    void update(int a, int b, T x, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (r <= a || b <= l) return;
        if (a <= l && r <= b) {
            lazy[k] = fm(lazy[k], x);
            eval(k, l, r);
        } else {
            update(a, b, x, 2 * k + 1, l, (l + r) / 2);
            update(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = fx(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (r <= a || b <= l) return ex;
        if (a <= l && r <= b) return node[k];
        T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return fx(vl, vr);
    }

    void print(int w = 4) {
        cout << "#node : " << endl;
        int prev = 0;
        for (int i = 1; i <= n; i *= 2) {
            for (int j = prev; j < prev + i; j++) {
                cout << setw(n * w / i) << setfill(' ');
                if (node[j] == ex) cout << "ex";
                else cout << node[j];
            }
            cout << endl;
            prev += i;
        }
        cout << "#lazy : " << endl;
        prev = 0;
        for (int i = 1; i <= n; i *= 2) {
            for (int j = prev; j < prev + i; j++) {
                cout << setw(n * w / i) << setfill(' ');
                if (lazy[j] == em) cout << "em";
                else cout << lazy[j];
            }
            cout << endl;
            prev += i;
        }
    }

   private:
    int n;
    vector<T> node, lazy;
    fn fx, fa, fm;
    T ex, em;
};

auto fx = [](auto l, auto r) { return min(l, r); };
auto fa = [](auto l, auto r) { return min(l, r); };
auto fm = [](auto l, auto r) { return min(l, r); };
vector<int> base((int)2e5, 1 << 28);
LazySegmentTree<int> segR(base, fx, fa, fm, 1 << 28, 1 << 28);
LazySegmentTree<int> segB(base, fx, fa, fm, 1 << 28, 1 << 28);

int main() {
    int N, Q; cin >> N >> Q;

    segR.update(0, N, N);
    segB.update(0, N, N);

    ll ans = (ll)(N - 2) * (N - 2);
    while (Q--) {
        // cout << "# ans : " << ans << endl;
        int q, x; cin >> q >> x;
        // cout << "--> query : " << q << ", " << x << endl;
        if (q == 1) {
            int b = segB.query(x - 1, x);
            if (x > 1) ans -= max(b - 2, 0);
            segR.update(0, b, x);
        } else {
            int r = segR.query(x - 1, x);
            if (x > 1) ans -= max(r - 2, 0);
            segB.update(0, r, x);
        }
        // cout << "--> ans : " << ans << endl;

        // cout << "-----------" << endl;
        // cout << "Right : " << endl;
        // REP(i, 0, N) cout << segR.query(i, i + 1) << " ";
        // cout << endl;
        // cout << "Bottom : " << endl;
        // REP(i, 0, N) cout << segB.query(i, i + 1) << " ";
        // cout << endl;
        // cout << "-----------" << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12048