#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename Monoid>
struct RMQandRUQ {
  RMQandRUQ(int sz, const Monoid UNITY) : UNITY(UNITY) {
    init(sz);
    dat.assign((n << 1) - 1, UNITY);
  }

  RMQandRUQ(const std::vector<Monoid> &a, const Monoid UNITY) : UNITY(UNITY) {
    int a_sz = a.size();
    init(a_sz);
    dat.resize((n << 1) - 1);
    for (int i = 0; i < a_sz; ++i) dat[n - 1 + i] = a[i];
    for (int i = n - 2; i >= 0; --i) dat[i] = std::min(dat[(i << 1) + 1], dat[(i << 1) + 2]);
  }

  void update(int a, int b, Monoid val) { update(a, b, val, 0, 0, n); }

  Monoid query(int a, int b) { return query(a, b, 0, 0, n); }

  Monoid operator[](const int idx) { return query(idx, idx + 1); }

  int find(int a, int b, Monoid val) { return find(a, b, val, 0, 0, n); }

private:
  int n = 1;
  const Monoid UNITY;
  std::vector<Monoid> dat, lazy;
  std::vector<bool> need_to_be_eval;

  void init(int sz) {
    while (n < sz) n <<= 1;
    lazy.assign((n << 1) - 1, UNITY);
    need_to_be_eval.assign((n << 1) - 1, false);
  }

  inline void evaluate(int node, int left, int right) {
    if (need_to_be_eval[node]) {
      dat[node] = lazy[node];
      if (node < n - 1) {
        lazy[(node << 1) + 1] = lazy[(node << 1) + 2] = lazy[node];
        need_to_be_eval[(node << 1) + 1] = need_to_be_eval[(node << 1) + 2] = true;
      }
      lazy[node] = UNITY;
      need_to_be_eval[node] = false;
    }
  }

  void update(int a, int b, Monoid val, int node, int left, int right) {
    evaluate(node, left, right);
    if (right <= a || b <= left) return;
    if (a <= left && right <= b) {
      lazy[node] = val;
      need_to_be_eval[node] = true;
      evaluate(node, left, right);
    } else {
      update(a, b, val, (node << 1) + 1, left, (left + right) >> 1);
      update(a, b, val, (node << 1) + 2, (left + right) >> 1, right);
      dat[node] = std::min(dat[(node << 1) + 1], dat[(node << 1) + 2]);
    }
  }

  Monoid query(int a, int b, int node, int left, int right) {
    evaluate(node, left, right);
    if (right <= a || b <= left) return UNITY;
    if (a <= left && right <= b) return dat[node];
    return std::min(query(a, b, (node << 1) + 1, left, (left + right) >> 1), query(a, b, (node << 1) + 2, (left + right) >> 1, right));
  }

  int find(int a, int b, Monoid val, int node, int left, int right) {
    evaluate(node, left, right);
    if (dat[node] > val || right <= a || b <= left) return -1;
    if (right - left == 1) return node - (n - 1);
    int res_l = find(a, b, val, (node << 1) + 1, left, (left + right) >> 1);
    return res_l == -1 ? find(a, b, val, (node << 1) + 2, (left + right) >> 1, right) : res_l;
    // int res_r = find(a, b, val, (node << 1) + 2, (left + right) >> 1, right);
    // return res_r == -1 ? find(a, b, val, (node << 1) + 1, left, (left + right) >> 1) : res_r;
  }
};

int main() {
  int n, q; cin >> n >> q;
  n -= 2;
  RMQandRUQ<int> row(n, n), col(n, n);
  ll ans = 1LL * n * n;
  while (q--) {
    int query, x; cin >> query >> x; x -= 2;
    if (query == 1) {
      int e = col[x];
      ans -= e;
      if (row[0] > x) row.update(0, e, x);
    } else if (query == 2) {
      int e = row[x];
      ans -= e;
      if (col[0] > x) col.update(0, e, x);
    }
    // REP(i, n) cout << row[i] << " \n"[i + 1 == n];
    // REP(i, n) cout << col[i] << " \n"[i + 1 == n];
    // cout << '\n';
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 11764