#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#define IFD(...)
#ifndef NDEBUG
#define NDEBUG
#endif
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <boost/hana/functional/fix.hpp>
using boost::hana::fix;
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, b, a) for (int i = (b); i >= (a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

struct intvl
{
    int l;
    int r;
};

struct mon
{
    using T = int;
    using T_act = int;

    //dontcare
    static T op(T a, T b)
    {
        return min(a, b);
    }
    static inline T id = 1'000'000;

    static T_act op_act(T_act u, T_act v)
    {
        return min(u, v);
    }
    static inline T_act id_act = 1'000'000;

    static T act(T a, T_act u, intvl lr)
    {
        return min(a, u);
    }
};

constexpr int log2_uint32(uint32_t x)
{
    if (x == 0)
    {
        return 0;
    }
    return 31 - __builtin_clz(x);
}

template <typename M>
struct seg_tree
{
    int n;
    using T = typename M::T;
    using T_act = typename M::T_act;

private:
    vector<T> data;
    vector<T_act> data_act;

    // ノードから区間への対応
    vector<intvl> intvl_s;

    // ノードの端点を得る
    intvl const &intvl_of_node(int const i)
    {
        return intvl_s[i];
    }

    // (2ベキでないときに出てくる)不要なノードならfalse
    bool is_valid_node(int const i)
    {
        intvl lr = intvl_of_node(i);
        return lr.l < lr.r;
    }

    // ノードiの値
    T get(int const i)
    {
        intvl lr = intvl_of_node(i);
        return M::act(data[i], data_act[i], lr);
    }

    // ノードiの親すべてから伝播
    void propagate(int const i)
    {
        for (int e = log2_uint32(i); e >= 1; e--)
        {
            int pa = i >> e;
            if (not is_valid_node(pa))
            {
                continue;
            }

            // assert(data[pa] == M::op(get(2 * pa), get(2 * pa + 1)));

            for (int ch = 2 * pa; ch <= 2 * pa + 1; ch++)
            {
                data_act[ch] = M::op_act(data_act[ch], data_act[pa]);
            }
            data[pa] = get(pa);
            data_act[pa] = M::id_act;

            // assert(data[pa] == M::op(get(2 * pa), get(2 * pa + 1)));
        }
    }

    // ノードiの親すべてに変更を反映
    void reflect_change(int i)
    {
        while (i > 1)
        {
            i /= 2;
            if (not is_valid_node(i))
            {
                break;
            }
            data[i] = M::op(get(2 * i), get(2 * i + 1));
        }
    }

    // ノードから区間の端点への対応を前計算
    void init_intvl_s()
    {
        for (int i = 0; i < n; i++)
        {
            intvl_s[n + i] = {i, i + 1};
        }
        for (int i = n - 1; i >= 1; i--)
        {
            intvl_s[i] = {intvl_s[2 * i].l, intvl_s[2 * i + 1].r};
        }
    }

public:
    // idで初期化
    explicit seg_tree(int const size)
        : n(size), data(2 * size, M::id), data_act(2 * size, M::id_act), intvl_s(2 * size)
    {
        init_intvl_s();
    }

    // a_sで初期化
    seg_tree(int const size, vector<T> const &a_s)
        : n(size), data(2 * size, M::id), data_act(2 * size, M::id_act), intvl_s(2 * size)
    {
        init_intvl_s();

        for (int i = 0; i < n; i++)
        {
            data[n + i] = a_s[i];
        }
        for (int i = n - 1; i >= 1; i--)
        {
            if (not is_valid_node(i))
            {
                continue;
            }
            data[i] = M::op(data[2 * i], data[2 * i + 1]);
        }
    }

    void act(T_act const u, intvl const lr)
    {
        assert(0 <= lr.l && lr.l <= lr.r && lr.r <= n);

        propagate(lr.l + n);
        propagate(lr.r - 1 + n);

        int l = lr.l + n, r = lr.r + n;
        while (l < r)
        {
            if (l & 1)
            {
                data_act[l] = M::op_act(data_act[l], u);
                l++;
            }
            if (r & 1)
            {
                r--;
                data_act[r] = M::op_act(data_act[r], u);
            }
            l /= 2;
            r /= 2;
        }

        reflect_change(lr.l + n);
        reflect_change(lr.r - 1 + n);
    }

    // 区間和を返す
    T query(intvl const lr)
    {
        assert(0 <= lr.l && lr.l < lr.r && lr.r <= n);

        propagate(lr.l + n);
        propagate(lr.r - 1 + n);

        int l = lr.l + n, r = lr.r + n;
        T ret_l = M::id, ret_r = M::id;
        while (l < r)
        {
            if (l & 1)
            {
                ret_l = M::op(ret_l, get(l));
                l++;
            }
            if (r & 1)
            {
                r--;
                ret_r = M::op(get(r), ret_r);
            }
            l /= 2;
            r /= 2;
        }

        return M::op(ret_l, ret_r);
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n, q;
    cin >> n >> q;

    vector<int> ini_data(n - 2, n - 2);
    vector segs(2, seg_tree<mon>(n - 2, ini_data));
    debug(n - 2);

    i64 ans = ((i64)n - 2) * (n - 2);
    rep(i, q)
    {
        int qtype;
        cin >> qtype;
        --qtype;
        int qx;
        cin >> qx;
        qx -= 2;

        debug(qx);
        int a = segs[qtype].query({qx, qx + 1});
        ans -= a;
        debug(a);
        segs[1 - qtype].act(qx, {0, a});
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 22720