#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
#define in(A, n)                                                                                                       \
    rep(i, n) {                                                                                                        \
        cin >> f;                                                                                                      \
        A.push_back(f);                                                                                                \
    }

void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll codeforces = 1;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
vector<vl> g(MAX_N);
vl A, B;
void input() { cin >> n >> q; }
// BEGIN CUT HERE
struct RUP {
    int n;
    vector<int> dat, laz;
    const int def = INT_MAX;
    RUP() {}
    RUP(int n_) { init(n_); }
    void init(int n_) {
        n = 1;
        while(n < n_)
            n *= 2;
        dat.clear();
        dat.resize(2 * n - 1, def);
        laz.clear();
        laz.resize(2 * n - 1, -1);
    }
    inline void eval(int len, int k) {
        if(laz[k] < 0)
            return;
        if(k * 2 + 1 < n * 2 - 1) {
            laz[k * 2 + 1] = laz[k];
            laz[k * 2 + 2] = laz[k];
        }
        dat[k] = laz[k];
        laz[k] = -1;
    }
    int update(int a, int b, int x, int k, int l, int r) {
        eval(r - l, k);
        if(r <= a || b <= l)
            return dat[k];
        if(a <= l && r <= b)
            return laz[k] = x;
        eval(r - l, k);
        dat[k] = min(update(a, b, x, k * 2 + 1, l, (l + r) / 2), update(a, b, x, k * 2 + 2, (l + r) / 2, r));
        return dat[k];
    }
    int query(int a, int b, int k, int l, int r) {
        eval(r - l, k);
        if(r <= a || b <= l)
            return def;
        if(a <= l && r <= b)
            return dat[k];
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
    void update(int a, int b, int x) { update(a, b, x, 0, 0, n); }
    int query(int a, int b) { return query(a, b, 0, 0, n); }
};
// END CUT HERE
void solve() {
    ans = (n - 2) * (n - 2);
    RUP rup1(n), rup2(n);
    rup1.update(0, n, n - 2);
    rup2.update(0, n, n - 2);
    rep(i, q) {
        cin >> x >> y;
        y -= 2;
        if(x == 1) {
            k = rup2.query(y, y + 1);
            ans -= k;
            if(rup1.query(0, n) > y)
                rup1.update(0, k + 1, y);
        } else {
            k = rup1.query(y, y + 1);
            ans -= k;
            if(rup2.query(0, n) > y)
                rup2.update(0, k + 1, y);
        }
    }

    print(ans);
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

Measured memory_bytes: 23180