#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

struct node
{
    bool dirty = false;

    int val = INF<int>, lazy = INF<int>;

    node(){}

    template<class base_t>
    node(const base_t& x)
    {
        val = x;
    }

    node(const node& l, const node& r)
    {
        val = min(l.val, r.val);
    }

    node& operator += (const node& p)
    {
        lazy = min(lazy, p.lazy);
        dirty = true;
        return *this;
    }

    void apply()
    {
        val = min(val, lazy);
        lazy = INF<int>;
        dirty = false;
    }
};

template<class node_t>
class segtree
{
private:
    inline int left(int root){ return 2 * root;}
    inline int right(int root){ return 2 * root + 1;}

    vector<node_t> t;
    int n;

    template<class base_t>
    void build(int root, int l, int r, const vector<base_t>& v)
    {
        if(l == r)
        {
            t[root] = node_t(v[l]);
            return;
        }

        int mid = (l + r) / 2;
        build(left(root), l, mid, v);
        build(right(root), mid + 1, r, v);
        t[root] = node_t(t[left(root)], t[right(root)]);
    }

    void build(int root, int l, int r)
    {
        if(l == r)
        {
            t[root] = node_t(n - 2);
            return;
        }

        int mid = (l + r) / 2;
        build(left(root), l, mid);
        build(right(root), mid + 1, r);
        t[root] = node_t(t[left(root)], t[right(root)]);
    }
        
    node_t query(int root, int l, int r, int ql, int qr)
    {
        if(l > qr || r < ql)
            return node_t();
    
        push(root, l, r);

        if(l >= ql && r <= qr)
            return t[root];
        
        int mid = (l + r) / 2;
        node_t a = query(left(root), l, mid, ql, qr);
        node_t b = query(right(root), mid + 1, r, ql, qr);
        return node_t(a, b);
    }
    
    void update(int root, int l, int r, int ql, int qr, const node_t& v)
    {
        push(root, l, r);

        if(l > qr || r < ql) return;

        if(l >= ql && r <= qr)
        {
            t[root] += v;
            push(root, l, r);
            return;
        }
        
        int mid = (l + r) / 2;
        update(left(root), l, mid, ql, qr, v);
        update(right(root), mid + 1, r, ql, qr, v);
        t[root] = node_t(t[left(root)], t[right(root)]);
    }

    inline void push(int root, int l, int r)
    {
        if(t[root].dirty)
        {
            if(l != r)
            {
                t[left(root)] += t[root];
                t[right(root)] += t[root];
            }
            t[root].apply();
        }
    }

public:
    segtree(int _n = 1) : n(_n)
    {
        t.resize(4 * n);
        build(1, 0, n - 1);
    }

    template<class base_t>
    segtree(const vector<base_t>& v) : n(LEN(v))
    {
        t.resize(4 * n);
        build(1, 0, n - 1, v);
    }

    void update(int l, int r, const node_t& v)
    {
        update(1, 0, n - 1, l, r, v);
    }

    void update(int p, const node_t& v)
    {
        update(1, 0, n - 1, p, p, v);
    }

    node_t query(int l, int r)
    {
        return query(1, 0, n - 1, l, r);
    }
    
    node_t query(int p)
    {
        return query(1, 0, n - 1, p, p);
    }
};


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    int n, q;
    cin >> n >> q;
    segtree<node> sv(n), sh(n);
    node up;
    up.lazy = 0;
    sh.update(0, up);
    sh.update(n - 1, up);
    sv.update(n - 1, up);
    sv.update(n - 1, up);

    ll ans = (n - 2LL) * (n - 2LL);

    while(q--)
    {
        int t, x;
        cin >> t >> x;
        if(--t)
        {
            int v = sv.query(x - 1).val; 
            ans -= v;
            up.lazy = x - 2;
            sh.update(0, v, up);
        }
        else
        {
            int v = sh.query(x - 1).val;
            ans -= v;
            up.lazy = x - 2;
            sv.update(0, v, up);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 21956