#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

template<class T> class LazySegmentTree {
    public:
    size_t n;       // 葉の数
    vector<T> data; // データ
    vector<T> lazy; // 遅延評価用
    T unit;         // 単位元
    T def;          // 初期値
    function<T(T, T)> update_func;      // 更新で使う処理
    function<T(T, T)> find_func;        // クエリで使う処理
    function<T(T, T)> lazy_prop_func;   // 遅延評価用の値を子ノードに伝播させる処理

    LazySegmentTree(
        size_t _n, T _unit, T _def,  
        function<T(T, T)> _update_func, 
        function<T(T, T)> _find_func, 
        function<T(T, T)> _lazy_prop_func
        ) : unit(_unit), def(_def), update_func(_update_func), find_func(_find_func), lazy_prop_func(_lazy_prop_func) {
        // 2のべき乗にする
        n = 1;
        while(n < _n) n <<= 1;
        data = vector<T>(2*n-1, _def);
        lazy = vector<T>(2*n-1, _def);
    }

    void eval(size_t k, size_t kl, size_t kr) {
        if(lazy[k] == def) return;
        data[k] = update_func(data[k], lazy[k]);
        if(kr - kl > 1){
            lazy[2*k+1] = lazy_prop_func(lazy[2*k+1], lazy[k]);
            lazy[2*k+2] = lazy_prop_func(lazy[2*k+1], lazy[k]);
        }
        lazy[k] = def;
    }

    void _update(size_t s, size_t t, size_t k, size_t kl, size_t kr, T x){
        eval(k, kl, kr);

        if(t <= kl || kr <= s) return;
        if(s <= kl && kr <= t) {
            lazy[k] = lazy_prop_func(lazy[k], x);
            eval(k, kl, kr);
        } else {
            size_t kc = (kl+kr)/2;
            _update(s, t, 2*k+1, kl, kc, x);
            _update(s, t, 2*k+2, kc, kr, x);
            data[k] = find_func(data[2*k+1], data[2*k+2]);
        }
    }

    void update(size_t s, size_t t, T x) {
        return _update(s, t, 0, 0, n, x);
    }

    T _find(size_t s, size_t t, size_t k, size_t kl, size_t kr){
        if(kr <= s || t <= kl) return unit;

        eval(k, kl, kr);
        if(s <= kl && kr <= t) return data[k];

        size_t kc = (kl+kr)/2;
        T vl = _find(s, t, 2*k+1, kl, kc);
        T vr = _find(s, t, 2*k+2, kc, kr);
        return find_func(vl, vr);
    }
    
    T find(size_t s, size_t t) {
        return _find(s, t, 0, 0, n);
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    LazySegmentTree<ll> row_tree(
        n+1, LINF, n, 
        [](ll a, ll b) { return min(a, b); }, 
        [](ll a, ll b) { return min(a, b); }, 
        [](ll a, ll b) { return min(a, b); }
    );
    LazySegmentTree<ll> column_tree(
        n+1, LINF, n, 
        [](ll a, ll b) { return min(a, b); }, 
        [](ll a, ll b) { return min(a, b); }, 
        [](ll a, ll b) { return min(a, b); }
    );
    row_tree.update(n, n+1, 1);
    column_tree.update(n, n+1, 1);
    ll ans = ll(n-2) * ll(n-2);
    
    int query, x;
    for(int i=0;i<q;++i) {
        cin >> query >> x;
        ll y = 2LL;
        if(query == 1) {
            y = row_tree.find(x, x+1);
            row_tree.update(x, x+1, 1);
            column_tree.update(1, y+1, x);
        } else {
            y = column_tree.find(x, x+1);
            column_tree.update(x, x+1, 1);
            row_tree.update(1, y+1, x);
        }
        ans -= max(0LL, y - 2LL);
    }

    cout << ans << endl;

}

Measured memory_bytes: 19548