#include <bits/stdc++.h>
#define FASTIO
using namespace std;

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }
        template <typename T>
        void pvec(const T& vec, size_t sz) const {
            for (size_t i = 0; i < sz; i++)
                std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        void pmat(const T& mat, size_t h, size_t w) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

template <class T, class E, class F, class G, class H, class P>
class LazySegmentTree {
private:
    const F f;
    const G g;
    const H h;
    const P p;
    const T tid;
    const E eid;
    std::vector<T> vec;
    std::vector<E> lazy;
    int sz;

public:
    explicit LazySegmentTree(
        int n, F f, G g, H h, P p, T tid, E eid) noexcept
        : f(f), g(g), h(h), p(p), tid(tid), eid(eid) {
        sz = 1;
        while (sz < n) sz <<= 1;
        vec.assign(sz * 2 - 1, tid);
        lazy.assign(sz * 2 - 1, eid);
    }
    T& operator[](int idx) noexcept {
        return vec[sz - 1 + idx];
    }
    void set_value(int idx, T val) noexcept {
        vec[sz - 1 + idx] = val;
    }
    void build() noexcept {
        for (int i = sz - 2; i >= 0; i--) {
            vec[i] = f(vec[i * 2 + 1], vec[i * 2 + 2]);
        }
    }
    void eval(int k, int l, int r) noexcept {
        if (lazy[k] == eid) return;
        if (r - l > 1) {
            lazy[k * 2 + 1] = h(lazy[k * 2 + 1], lazy[k]);
            lazy[k * 2 + 2] = h(lazy[k * 2 + 2], lazy[k]);
        }
        vec[k] = g(vec[k], p(lazy[k], r - l));
        lazy[k] = eid;
    }
    void update(int a, int b, E x) noexcept {
        _update(a, b, x, 0, 0, sz);
    }
    T query(int a, int b) noexcept {
        return _query(a, b, 0, 0, sz);
    }

private:
    T _update(int a, int b, E x, int k, int l, int r) noexcept {
        eval(k, l, r);
        if (b <= l || r <= a) return vec[k];
        if (a <= l && r <= b) {
            lazy[k] = h(lazy[k], x);
            return g(vec[k], p(lazy[k], r - l));
        }
        else {
            T t1 = _update(a, b, x, k * 2 + 1, l, (l + r) >> 1);
            T t2 = _update(a, b, x, k * 2 + 2, (l + r) >> 1, r);
            return vec[k] = f(t1, t2);
        }
    }
    T _query(int a, int b, int k, int l, int r) noexcept {
        if (b <= l || r <= a) return tid;
        eval(k, l, r);
        if (a <= l && r <= b) {
            return vec[k];
        }
        else {
            T t1 = _query(a, b, k * 2 + 1, l, (l + r) >> 1);
            T t2 = _query(a, b, k * 2 + 2, (l + r) >> 1, r);
            return f(t1, t2);
        }
    }
};


void solve() {
    ll N, Q;
    cin >> N >> Q;

    auto opf = [](ll a, ll b) -> ll { return min(a, b); };
    auto opg = [](ll a, ll b) -> ll { return min(a, b); };
    auto oph = [](ll a, ll b) -> ll { return min(a, b); };
    auto opp = [](ll a, int k) -> ll { return a; };
    LazySegmentTree seg_x(N, opf, opg, oph, opp, L_INF, L_INF);
    LazySegmentTree seg_y(N, opf, opg, oph, opp, L_INF, L_INF);

    for (ll i = 0; i < N; i++) {
        seg_x[i] = N - 2;
        seg_y[i] = N - 2;
    }
    seg_x.build();
    seg_y.build();

    ll ans = (N - 2) * (N - 2);
    for (ll i = 0; i < Q; i++) {
        int q;
        cin >> q;
        if (q == 1) {
            int a;
            cin >> a;
            --a;
            ll t = seg_x.query(a, a + 1);
            ans -= t;
            seg_y.update(0, t + 1, a - 1);
            seg_x.update(a, a + 1, 0);
        }
        else {
            int a;
            cin >> a;
            --a;
            ll t = seg_y.query(a, a + 1);
            ans -= t;
            seg_x.update(0, t + 1, a - 1);
            seg_y.update(a, a + 1, 0);
        }
        // for (ll i = 0; i < N; i++) {
        //     cout << seg_x.query(i, i + 1) << " ";
        // }
        // prints()();
        // for (ll i = 0; i < N; i++) {
        //     cout << seg_y.query(i, i + 1) << " ";
        // }
        // prints()();
        // prints()();
    }

    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}

Measured memory_bytes: 19568