//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define asd(n) rep(i, 0, n)
#define jkl(n) rep(j, 0, n)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas

namespace IO {

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a);

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a);

    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e9;
struct segtree_max {
    vi t;
    int n;
    void build() {  // build the tree
        for (int i = n - 1; i > 0; --i) t[i] = max(t[i<<1], t[i<<1|1]);
    }
    segtree_max(){}
    segtree_max(vi a) {
        n = a.size();
        t.resize(n * 2);
        rep(i, 0, n) t[i + n] = a[i];
        build();
    }
    void modify(int p, int value) {  // set value at position p
        for (t[p += n] = value; p > 1; p >>= 1) t[p>>1] = max(t[p], t[p^1]);
    }

    int query(int l, int r) {  // sum on interval [l, r)
        int res = -INF;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l&1) chkmax(res, t[l++]);
            if (r&1) chkmax(res, t[--r]);
        }
        return res;
    }
};
struct fenwick {
    vi tree;
    fenwick(vi a) {
        tree.resize(a.size(), 0);
        rep(i, 0, a.size()) incr(i, a[i]);
    }
    void incr(int i, int x) {
        for (;i < tree.size(); i |= i + 1)tree[i] += x;
    }
    int sum(int r) {
        int res = 0;
        while (r >= 0) {
            res += tree[r];
            r = (r&(r + 1)) - 1;
        }
        return res;
    }
    int get(int l, int r) { // []
        return sum(r) - sum(l - 1);
    }
};
void solve() {
    int n, q;
    cin >> n >> q;
    vector<segtree_max> a(2, segtree_max(vi(n, 0)));
    a[0].modify(n - 1, n);
    a[1].modify(n - 1, n);
    vvi u(2, vi(n, 0));
    u[0][n - 1] = u[1][n - 1] = n;
    int fl = 0;
    int c2 = 1;
    rep(tt, 0, q) {
        int t, x;
        cin >> t >>x;
        --x;
        fl = t == 1;
        if (u[fl][x]) continue;
        int L = 0, R = n;
        while (R - L > 1) {
            int m = (R + L) / 2;
            int e = a[fl^1].query(0, m);
            if (a[fl^1].query(0, m) <= x) L = m;
            else R = m;
        }
        if (fl == 1) ++c2;
        a[fl].modify(x, L);
        u[fl][x] = L;
    }
    int ans = 0;
    asd(n) ans += u[0][i] + u[1][i];
    put(n * n - ans - count(all(u[0]), 0) - count(all(u[1]), 0) + 2);
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;

    while (q--) solve();
}


Measured memory_bytes: 13744