/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Aman
 */


#include<bits/stdc++.h>

using namespace std;

#include <iostream>


#define ll   long long
#define F first
#define S second

void __print(int x) { cout << x; }

void __print(long x) { cout << x; }

void __print(long long x) { cout << x; }

void __print(unsigned x) { cout << x; }

template<typename T, typename V>
void __print(const pair<T, V> &x) {
    cout << '{';
    __print(x.first);
    cout << ',';
    __print(x.second);
    cout << '}';
}

template<typename T>
void __print(const T &x) {
    int f = 0;
    cout << '{';
    for (auto &i: x) cout << (f++ ? "," : ""), __print(i);
    cout << "}";
}

void _print() { cout << "]\n"; }

template<typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cout << ", ";
    _print(v...);
}


template<class S,
        S (*op)(S, S),
        S (*e)(),
        class F,
        S (*mapping)(F, S),
        F (*composition)(F, F),
        F (*id)()>
struct lazy_segtree {
public:

    lazy_segtree(const std::vector<S> &v) : _n(int(v.size())) {
        log = log2(_n) + 2;
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        lz = std::vector<F>(size, id());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }
    S get(int p) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        return d[p];
    }

    void apply(int l, int r, F f) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return;

        l += size;
        r += size;

        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }

        {
            int l2 = l, r2 = r;
            while (l < r) {
                if (l & 1) all_apply(l++, f);
                if (r & 1) all_apply(--r, f);
                l >>= 1;
                r >>= 1;
            }
            l = l2;
            r = r2;
        }

        for (int i = 1; i <= log; i++) {
            if (((l >> i) << i) != l) update(l >> i);
            if (((r >> i) << i) != r) update((r - 1) >> i);
        }
    }

private:
    int _n, size, log;
    std::vector<S> d;
    std::vector<F> lz;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }

    void all_apply(int k, F f) {
        d[k] = mapping(f, d[k]);
        if (k < size) lz[k] = composition(f, lz[k]);
    }

    void push(int k) {
        all_apply(2 * k, lz[k]);
        all_apply(2 * k + 1, lz[k]);
        lz[k] = id();
    }
};


#ifdef LOCAL
#else
#define dbg(x...)
#endif
struct F {
    int b; // denotes the mapping "multiply by b"
};
using S = int;

S op(S x, S y) { return min(x, y); }

S e() { return 1e9; }

S mapping(F f, S x) { return min(f.b, x); }

F composition(F f, F g) { return F{min(f.b, g.b)}; }

F id() { return F{(int) 1e7}; }

class FSimplifiedReversi {
public:

    void solve2(std::istream &cin, std::ostream &cout) {

        int n, q;
        cin >> n >> q;
        vector<int> col(n + 1, n), row(n + 1, n);
        col[n] = 1, row[n] = 1;
        lazy_segtree<S, op, e, F, mapping, composition, id> C(col), R(row);
        ll ans = (ll) (n - 2) * (n - 2);
        for (int i = 0; i < q; ++i) {
            int t, x;
            cin >> t >> x;
            if (t == 1) {
                int hi = C.get(x);
                ans -= hi - 2;
                R.apply(1, hi, F{x});
                C.apply(x, x, F{1});
            } else {
                int hi = R.get(x);
                ans -= hi - 2;
                C.apply(1, hi, F{x});
                R.apply(x, x, F{1});
            }
        }
        cout << ans;


    }

    void solve(std::istream &cin, std::ostream &cout) {
        ll t = 1;
//            cin >> t;
        while (t--) {
            solve2(cin, cout);
        }
    }

};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    FSimplifiedReversi solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 17280