#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ull unsigned ll
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
const int N = 2e5 + 10;
const ll M = 998244353;

int rst[4 * N], cst[4 * N], rlazy[4 * N], clazy[4 * N];


void rpush(int v) {
    int left = v << 1, right = left | 1;
    if (rlazy[v] != INT_MAX) {
        rst[left] = min(rst[left], rlazy[v]);
        rst[right] = min(rst[right], rlazy[v]);
        rlazy[left] = min(rlazy[left], rlazy[v]);
        rlazy[right] = min(rlazy[right], rlazy[v]);
        rlazy[v] = INT_MAX;
    }
}

void rupdate(int l, int r, int val, int sl, int sr, int v) {
    if (l > sr || r < sl)
        return;
    if (l <= sl && sr <= r) {
        rst[v] = min(rst[v], val);
        rlazy[v] = min(rlazy[v], val);
        return;
    }
    rpush(v);
    int md = (sl + sr) >> 1, left = v << 1, right = left | 1;
    rupdate(l, r, val, sl, md, left);
    rupdate(l, r, val, md + 1, sr, right);
    rst[v] = min(rst[left], rst[right]);
}

int rquery(int l, int r, int sl, int sr, int v) {
    if (l > sr || r < sl)
        return INT_MAX;
    if (l <= sl && sr <= r)
        return rst[v];
    rpush(v);
    int md = (sl + sr) >> 1, left = v << 1, right = left | 1;
    return min(rquery(l, r, sl, md, left), rquery(l, r, md + 1, sr, right));
}

void cpush(int v) {
    int left = v << 1, right = left | 1;
    if (clazy[v] != INT_MAX) {
        cst[left] = min(cst[left], clazy[v]);
        cst[right] = min(cst[right], clazy[v]);
        clazy[left] = min(clazy[left], clazy[v]);
        clazy[right] = min(clazy[right], clazy[v]);
        clazy[v] = INT_MAX;
    }
}

void cupdate(int l, int r, int val, int sl, int sr, int v) {
    if (l > sr || r < sl)
        return;
    if (l <= sl && sr <= r) {
        cst[v] = min(cst[v], val);
        clazy[v] = min(clazy[v], val);
        return;
    }
    cpush(v);
    int md = (sl + sr) >> 1, left = v << 1, right = left | 1;
    cupdate(l, r, val, sl, md, left);
    cupdate(l, r, val, md + 1, sr, right);
    cst[v] = min(cst[left], cst[right]);
}

int cquery(int l, int r, int sl, int sr, int v) {
    if (l > sr || r < sl)
        return INT_MAX;
    if (l <= sl && sr <= r)
        return cst[v];
    cpush(v);
    int md = (sl + sr) >> 1, left = v << 1, right = left | 1;
    return min(cquery(l, r, sl, md, left), cquery(l, r, md + 1, sr, right));
}

void init(int n) {
    fill(rst, rst + 4 * N, n);
    fill(cst, cst + 4 * N, n);
    fill(rlazy, rlazy + 4 * N, INT_MAX);
    fill(clazy, clazy + 4 * N, INT_MAX);
}

int main() {
    ll n, q;
    cin >> n >> q;
    init(n);
    ll black = (n - 2) * (n - 2);
    for (int i = 0; i < q; ++i) {
        int x, y;
        cin >> x >> y;
        if (x == 1) {   //column query and row update
            int firstWhite = cquery(y, y, 1, n, 1);
            black -= (firstWhite - 2);
            rupdate(1, firstWhite, y, 1, n, 1);
            cupdate(y, y, 2, 1, n, 1);
        } else {
            int firstWhite = rquery(y, y, 1, n, 1);
            black -= (firstWhite - 2);
            cupdate(1, firstWhite, y, 1, n, 1);
            rupdate(y, y, 1, 1, n, 1);
        }
    }
    cout << black << endl;
}

Measured memory_bytes: 16156