#include <bits/stdc++.h>

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}
class LazySegmentTree {
    private:
        LL n;
        vector<LL> node, lazy;
        vector<bool> lazyFlag;

    public:
        LazySegmentTree(vector<LL> v) {
            LL sz = (LL) v.size();
            n = 1;
            while (n < sz) n *= 2;
            node.resize(2 * n - 1);
            lazy.resize(2 * n - 1, INF);
            lazyFlag.resize(2 * n - 1, false);

            for (LL i = 0; i < sz; i++) node[i + n - 1] = v[i];
            for (LL i = n - 2; i >= 0; i--) node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
        }

        void lazyEvaluate(LL k, LL l, LL r) {
            if (lazyFlag[k]) {
                node[k] = min(node[k], lazy[k]);
                if (r - l > 1) {
                    lazy[k * 2 + 1] = min(lazy[k * 2 + 1], lazy[k]);
                    lazy[k * 2 + 2] = min(lazy[k * 2 + 2], lazy[k]);
                    lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
                }
                lazyFlag[k] = false;
            }
        }

        void update(LL a, LL b, LL x, LL k = 0, LL l = 0, LL r = -1) {
            if (r < 0) r = n;
            lazyEvaluate(k, l, r);
            if (b <= l || r <= a) return;
            if (a <= l && r <= b) {
                lazy[k] = min(lazy[k], x);
                lazyFlag[k] = true;
                lazyEvaluate(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] = min(node[2 * k + 1], node[2 * k + 2]);
            }
        }

        LL find(LL a, LL b, LL k = 0, LL l = 0, LL r = -1) {
            if (r < 0) r = n;
            lazyEvaluate(k, l, r);
            if (b <= l || r <= a) return INF;
            if (a <= l && r <= b) return node[k];
            LL vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
            LL vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
};

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

    LL N, Q;
    cin >> N >> Q;

    vector<LL> v(N);
    for(int i = 0; i < N; ++i) {
        v[i] = N;
    }

    LazySegmentTree c(v);
    LazySegmentTree l(v);

    LL res = (N - 2) * (N - 2);
    while(Q--) {
        int a, b;
        cin >> a >> b;
        if(a == 1) {
            int m = l.find(b, b + 1);
            res -= m - 2;
            c.update(1, m, b);
        } else {
            int m = c.find(b, b + 1);
            res -= m - 2;
            l.update(1, m, b);
        }
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 22912