#include <bits/stdc++.h>
using namespace std;
// #pragma GCC target("arch=skylake-avx512")
// export CPLUS_INCLUDE_PATH="/Users/shuzaei/Desktop/ac-library"
// /usr/bin/env python3 "/Users/shuzaei/Desktop/ac-library/expander.py"
// /Users/shuzaei/Desktop/Solve.cpp
// #include <atcoder/all>
// using namespace atcoder;

#pragma region template

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T> using pvector = vector<pair<T, T>>;
template <class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr const ll dx[4] = {1, 0, -1, 0};
constexpr const ll dy[4] = {0, 1, 0, -1};
constexpr const ll MOD = 1e9 + 7;
constexpr const ll mod = 998244353;
constexpr const ll INF = 1LL << 60;
constexpr const ll inf = 1 << 30;
constexpr const char rt = '\n';
constexpr const char sp = ' ';
#define rt(i, n) (i == (ll)(n) -1 ? rt : sp)
#define len(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ifn(x) if (not(x))
#define elif else if
#define elifn else ifn
#define fi first
#define se second
#define uniq(x) (sort(all(x)), (x).erase(unique(all(x)), (x).end()))
#define bis(x, y) ((ll)(lower_bound(all(x), y) - (x).begin()))

using graph = vector<vector<ll>>;
template <class T> using wgraph = vector<vector<pair<ll, T>>>;
bool __DIRECTED__ = true;
bool __ZERO_INDEXED__ = false;
istream &operator>>(istream &is, graph &g) {
    ll a, b;
    is >> a >> b;
    if (__ZERO_INDEXED__ == false) a--, b--;
    g[a].pb(b);
    if (__DIRECTED__ == false) g[b].pb(a);
    return is;
}
template <class T> istream &operator>>(istream &is, wgraph<T> &g) {
    ll a, b;
    T c;
    is >> a >> b >> c;
    if (__ZERO_INDEXED__ == false) a--, b--;
    g[a].pb({b, c});
    if (__DIRECTED__ == false) g[b].pb({a, c});
    return is;
}

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

// Debug
#define debug(...)                                                                                 \
    {                                                                                              \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                                         \
        for (auto &&__i : {__VA_ARGS__}) cerr << "[" << __i << "] ";                               \
        cerr << rt;                                                                                \
    }

#define dumpi(a, h, w)                                                                             \
    {                                                                                              \
        cerr << __LINE__ << ": " << #a << " = [" << rt;                                            \
        rep(__i, h) {                                                                              \
            if (__i) cerr << ",\n";                                                                \
            cerr << "[";                                                                           \
            rep(__j, w) {                                                                          \
                if (__j) cerr << ", ";                                                             \
                if (abs(a[__i][__j]) >= INF / 2 and a[__i][__j] <= -INF / 2) cerr << '-';          \
                if (abs(a[__i][__j]) >= INF / 2) cerr << "∞";                                      \
                else                                                                               \
                    cerr << a[__i][__j];                                                           \
            }                                                                                      \
            cerr << "]" << rt;                                                                     \
        }                                                                                          \
        cerr << "\n]" << rt;                                                                       \
    }

#define vdumpi(a, n)                                                                               \
    {                                                                                              \
        cerr << __LINE__ << ": " << #a << " = [";                                                  \
        rep(__i, n) {                                                                              \
            if (__i) cerr << ", ";                                                                 \
            if (abs(a[__i]) >= INF / 2 and a[__i] <= -INF / 2) cerr << '-';                        \
            if (abs(a[__i]) >= INF / 2) cerr << "∞";                                               \
            else                                                                                   \
                cerr << a[__i];                                                                    \
        }                                                                                          \
        cerr << "]" << rt;                                                                         \
    }

#define dump(a, h, w)                                                                              \
    {                                                                                              \
        cerr << __LINE__ << ": " << #a << " = [" << rt;                                            \
        rep(__i, h) {                                                                              \
            if (__i) cerr << ",\n";                                                                \
            cerr << "[";                                                                           \
            rep(__j, w) {                                                                          \
                if (__j) cerr << ", ";                                                             \
                cerr << a[__i][__j];                                                               \
            }                                                                                      \
            cerr << "]";                                                                           \
        }                                                                                          \
        cerr << "\n]" << rt;                                                                       \
    }

#define vdump(a, n)                                                                                \
    {                                                                                              \
        cerr << __LINE__ << ": " << #a << " = [";                                                  \
        rep(__i, n) {                                                                              \
            if (__i) cerr << ", ";                                                                 \
            cerr << a[__i];                                                                        \
        }                                                                                          \
        cerr << "]" << rt;                                                                         \
    }

template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
    is >> p.first >> p.second;
    return is;
}
template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &p) {
    os << p.first << ' ' << p.second;
    return os;
}

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define rep(i, n) for (ll i = 0, _##i = (n); i < _##i; ++i)
#define each(i, a) for (auto &&i : a)

// Stream
#define fout(n) cout << fixed << setprecision(n)
struct io {
    io() { cin.tie(nullptr), ios::sync_with_stdio(false); }
} io;

// Speed
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast,unroll-loops")

// Math
inline constexpr ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }

inline constexpr ll modulo(const ll n, const ll m = MOD) {
    ll k = n % m;
    return k + m * (k < 0);
}
inline constexpr ll chmod(ll &n, const ll m = MOD) {
    n %= m;
    return n += m * (n < 0);
}
inline constexpr ll mpow(ll a, ll n, const ll m = MOD) {
    ll r = 1;
    rep(i, 64) {
        if (n & (1LL << i)) r *= a;
        chmod(r, m);
        a *= a;
        chmod(a, m);
    }
    return r;
}
inline ll inv(const ll n, const ll m = MOD) {
    ll a = n, b = m, x = 1, y = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        x -= t * y;
        swap(x, y);
    }
    return modulo(x, m);
}

#pragma endregion

template <class T> struct SegmentTreeBeats {
    struct Beats {
        T first_max, second_max;
        ll cnt;
        Beats(const T &a, const T &b = def_beats, ll c = 1) : first_max(a), second_max(b), cnt(c) {}
        Beats operator+(const Beats &a) const {
            if (c(first_max, a.first_max))
                return {a.first_max, max(first_max, a.second_max, c), a.cnt};
            else if (c(a.first_max, first_max))
                return {first_max, max(second_max, a.first_max, c), cnt};
            return {first_max, max(second_max, a.second_max, c), cnt + a.cnt};
        }
    };
    inline T f(const T &a, const T &b) const { return a + b; }
    inline void m(T &data, Beats &beats, const T &val) {
        data += beats.cnt * (val - beats.first_max);
        beats.first_max = val;
    }
    static inline bool c(const T &a, const T &b);
    static const T def_value, def_beats, identity;
    ll size = 1, rank = 0;
    vector<T> data, lazy;
    vector<Beats> beats;
    SegmentTreeBeats(ll n) {
        while (size < n) {
            size *= 2;
            rank++;
        }
        data.assign(size * 2, def_value);
        lazy.assign(size * 2, def_value);
        beats.assign(size * 2, def_value);
        for (ll i = size; --i;) beats[i] = beats[i * 2] + beats[i * 2 + 1];
    }
    SegmentTreeBeats(const vector<T> &v) {
        while (size < v.size()) {
            size *= 2;
            rank++;
        }
        data.assign(size * 2, def_value);
        lazy.assign(size * 2, def_value);
        beats.assign(size * 2, def_beats);
        for (ll i = 0; i < v.size(); i++) {
            data[size + i] = v[i];
            beats[size + i] = v[i];
        }
        for (ll i = size; --i;) {
            data[i] = f(data[i * 2], data[i * 2 + 1]);
            beats[i] = beats[i * 2] + beats[i * 2 + 1];
        }
    }
    inline void _push(ll at) {
        if (lazy[at] != def_value) {
            if (c(lazy[at], beats[at * 2].first_max)) {
                m(data[at * 2], beats[at * 2], lazy[at]);
                lazy[at * 2] = min(lazy[at], lazy[at * 2], c);
            }
            if (c(lazy[at], beats[at * 2 + 1].first_max)) {
                m(data[at * 2 + 1], beats[at * 2 + 1], lazy[at]);
                lazy[at * 2 + 1] = min(lazy[at], lazy[at * 2 + 1], c);
            }
            lazy[at] = def_value;
        }
    }
    inline void push(ll at) {
        if (!at) return;
        for (ll i = 32 - __builtin_clz(at); --i;) _push(at >> i);
    }
    inline void _update(ll at) {
        data[at] = f(data[at * 2], data[at * 2 + 1]);
        beats[at] = beats[at * 2] + beats[at * 2 + 1];
    }
    inline void update(ll at) {
        while (at /= 2) _update(at);
    }
    inline T operator[](ll at) {
        at += size;
        push(at);
        return data[at];
    }
    inline void set(ll at, const T &val) {
        at += size;
        push(at);
        data[at] = val;
        beats[at] = val;
        update(at);
    }
    inline void chmin(ll l, ll r, const T &val) {
        l += size;
        r += size;
        ll at = 1, rnk = rank;
        while (at) {
            if (l < (at + 1) << rnk && at << rnk < r && c(val, beats[at].first_max)) {
                if (at < size) _push(at);
                if (l <= at << rnk && (at + 1) << rnk <= r && c(beats[at].second_max, val) &&
                    c(val, beats[at].first_max)) {
                    m(data[at], beats[at], val);
                    lazy[at] = val;
                } else {
                    at *= 2;
                    rnk--;
                    continue;
                }
            }
            while (at & 1) {
                at /= 2;
                rnk++;
                _update(at);
            }
            if (!at) return;
            at++;
        }
    }
    T get_f(ll l, ll r) {
        if (l >= r) return identity;
        T L = identity, R = identity;
        l += size;
        r += size;
        push(l);
        push(r - 1);
        for (; l < r; l /= 2, r /= 2) {
            if (l & 1) L = f(L, data[l++]);
            if (r & 1) R = f(data[--r], R);
        }
        return f(L, R);
    }
    T get_max(ll l, ll r) {
        if (l >= r) return def_beats;
        T L = def_beats, R = def_beats;
        l += size;
        r += size;
        push(l);
        push(r - 1);
        for (; l < r; l /= 2, r /= 2) {
            if (l & 1) L = max(L, beats[l++].first_max, c);
            if (r & 1) R = max(beats[--r].first_max, R, c);
        }
        return max(L, R, c);
    }
};
template <class T> const T SegmentTreeBeats<T>::def_value = numeric_limits<T>::max();
template <class T> const T SegmentTreeBeats<T>::def_beats = numeric_limits<T>::min();
template <class T> const T SegmentTreeBeats<T>::identity = T();
template <class T> bool SegmentTreeBeats<T>::c(const T &a, const T &b) { return a < b; }

SegmentTreeBeats<int> tate(200000), yoko(200000);
signed main() {
    ll N, Q, A, B, res;
    cin >> N >> Q;
    res = (N - 2) * (N - 2);
    rep(i, N - 2) tate.set(i, N - 2), yoko.set(i, N - 2);
    rep(i, Q) {
        // rep(i, N - 2) debug(tate.get_max(i, i + 1));
        // rep(i, N - 2) debug(yoko.get_max(i, i + 1));
        cin >> A >> B;
        if (A == 1) {
            ll l = yoko.get_max(B - 2, B - 1);
            res -= l;
            tate.chmin(0, l, B - 2);
        } else {
            ll l = tate.get_max(B - 2, B - 1);
            res -= l;
            yoko.chmin(0, l, B - 2);
        }
        // debug(res);
    }
    cout << res << rt;
}

Measured memory_bytes: 27688