#define MOD_TYPE 2

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

#if 0
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

struct io_init
{
  io_init()
  {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(30) << setiosflags(ios::fixed);
  };
} io_init;
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

// 0-indexed
template <typename T>
struct BIT
{
  int n;
  vector<T> bit[2];
  BIT(int n) : n(n)
  {
    for (int p = 0; p < 2; p++)
      bit[p].assign(n, 0);
  }

  void add_sub(int p, int i, T x)
  {
    for (int idx = i; idx < n + 1; idx += (idx & -idx))
      bit[p][idx - 1] += x;
  }
  // [l,r) に加算
  void add(int l, int r, T x)
  {
    ++l, ++r;
    add_sub(0, l, -x * (l - 1));
    add_sub(0, r, x * (r - 1));
    add_sub(1, l, x);
    add_sub(1, r, -x);
  }
  T sum_sub(int p, int i)
  {
    T s(0);
    for (int idx = i; idx > 0; idx -= (idx & -idx))
      s += bit[p][idx - 1];
    return s;
  }
  T sum(int i)
  {
    ++i;
    return sum_sub(0, i) + sum_sub(1, i) * i;
  }
  T get(int i) { return sum(i) - sum(i - 1); }
  void display()
  {
    rep(i, n) cerr << get(i) << " ";
    cerr << "\n";
  }
};

void solve()
{
  ll n, q;
  cin >> n >> q;
  ll ans = 0;
  ll R = n - 2, C = n - 2;
  BIT<ll> bit_r(n - 1), bit_c(n - 1);
  bit_r.add(0, n - 1, n - 2);
  bit_c.add(0, n - 1, n - 2);

  rep(qi, q)
  {
    int ty;
    ll x;
    cin >> ty >> x;
    x -= 2;/*
    dbg(ty);
    dbg(x);*/
    if (ty == 1) // 縦
    {
      ans += bit_c.get(x);
      if (C > x)
      {
        C = x;
        bit_r.add(0, R, x - bit_r.get(0));
      }
    }
    else // 横
    {
      ans += bit_r.get(x);
      if (R > x)
      {
        R = x;
        bit_c.add(0, C, x - bit_c.get(0));
      }
    }/*
    dbg(ans);
    dbg(R);
    dbg(C);
    bit_r.display();
    bit_c.display();*/
  }
  ans = (n - 2) * (n - 2) - ans;
  cout << ans << "\n";
}

int main()
{
  solve();
}


Measured memory_bytes: 9524