#include<cstdio>
#include<set>
#include<utility>
using namespace std;
typedef pair<int, int> P;

int n, q;
set<P> v[2];

int main() {
    scanf("%d %d", &n, &q);
    v[0].emplace(n, n);
    v[1].emplace(n, n);
    long ans = static_cast<long>(n - 2) * (n - 2);
    for (int i = 0; i < q; i++) {
        int l, x, tmp;
        scanf("%d %d", &l, &x);
        tmp = v[l - 1].upper_bound(P(x, 0))->second;
        ans -= tmp - 2;
        v[l % 2].emplace(tmp, x);
    }

    printf("%ld\n", ans);
    return 0;
}
