/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, q;
int hor[MAXN * 8], ver[MAXN * 8], lazyHor[MAXN * 8], lazyVer[MAXN * 8];

void build(int k, int l, int r) {
    if (l > r) return;
    if (l == r) {
        hor[k] = ver[k] = n;
        lazyHor[k] = lazyVer[k] = 1000000;
        return;
    }
    int m = (l + r) >> 1;
    build(k*2, l, m);
    build(k*2+1, m+1, r);
    lazyHor[k] = lazyVer[k] = 1000000;
    hor[k] = min(hor[k*2], hor[k*2+1]);
    ver[k] = min(ver[k*2], ver[k*2+1]);
}

void lazyUpdateHor(int k, int l, int r) {
    if (l > r) return;
    if (lazyHor[k] == 1000000) return;
    hor[k] = min(hor[k], lazyHor[k]);
    if (l < r) {
        lazyHor[k*2] = min(lazyHor[k*2], lazyHor[k]);
        lazyHor[k*2+1] = min(lazyHor[k*2+1], lazyHor[k]);
    }
    lazyHor[k] = 1000000;
}

void lazyUpdateVer(int k, int l, int r) {
    if (l > r) return;
    if (lazyVer[k] == 1000000) return;
    ver[k] = min(ver[k], lazyVer[k]);
    if (l < r) {
        lazyVer[k*2] = min(lazyVer[k*2], lazyVer[k]);
        lazyVer[k*2+1] = min(lazyVer[k*2+1], lazyVer[k]);
    }
    lazyVer[k] = 1000000;
}

int getVer(int k, int l, int r, int u) {
    lazyUpdateVer(k, l, r);
    if (l > r || r < u || u < l) return -1e9;
    if (l == r) return ver[k];
    int m = (l + r) >> 1;
    if (u <= m) return getVer(k*2, l, m, u);
    return getVer(k*2+1, m+1, r, u);
}

int getHor(int k, int l, int r, int u) {
    lazyUpdateHor(k, l, r);
    if (l > r || r < u || u < l) return -1e9;
    if (l == r) return hor[k];
    int m = (l + r) >> 1;
    if (u <= m) return getHor(k*2, l, m, u);
    return getHor(k*2+1, m+1, r, u);
}

void updateVer(int k, int l, int r, int u, int v, int val) {
    lazyUpdateVer(k, l, r);
    if (l > r || r < u || v < l) return;
    if (u <= l && r <= v) {
        lazyVer[k] = val;
        lazyUpdateVer(k, l, r);
        return;
    }
    int m = (l + r) >> 1;
    updateVer(k*2, l, m, u, v, val);
    updateVer(k*2+1, m+1, r, u, v, val);
    ver[k] = min(ver[k*2], ver[k*2+1]);
}

void updateHor(int k, int l, int r, int u, int v, int val) {
    lazyUpdateHor(k, l, r);
    if (l > r || r < u || v < l) return;
    if (u <= l && r <= v) {
        lazyHor[k] = val;
        lazyUpdateHor(k, l, r);
        return;
    }
    int m = (l + r) >> 1;
    updateHor(k*2, l, m, u, v, val);
    updateHor(k*2+1, m+1, r, u, v, val);
    hor[k] = min(hor[k*2], hor[k*2+1]);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> q;
    build(1,1,n);
    ll res = (ll) (n-2) * (n-2);
    while (q--) {
        int u, v;
        cin >> u >> v;
        if (u == 1) {
            int x = getVer(1,1,n,v);
            res -= max(0, x - 2);
            if (2 <= x-1) updateHor(1,1,n,2,x-1,v);
        } else {
            int x = getHor(1,1,n,v);
            res -= max(0, x - 2);
            if (2 <= x-1) updateVer(1,1,n,2,x-1,v);
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 11812