#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int int64_t
#define double long double
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using reverse_queue = priority_queue<T, vector<T>, greater<T>>;
mt19937_64 rnd(time(0));
const int64_t FIXED_RANDOM = rnd();
template<typename T> struct custom_hash{T operator()(T x)const{return (T) x^FIXED_RANDOM;}}; // check hash in whether int64 or int32
template<typename T1, typename T2> using hash_map = gp_hash_table<T1, T2, custom_hash<T1>>;
// Tao luyện kỹ thuật trong 8 năm mày luyện kỹ thuật trong buồng tắm nam
const int MAXN = (int) 2e5 + 2;
const int INF = numeric_limits<int>::max() >> 1;
const int MOD = (int) 998244353;
struct lazy_segment_tree{
  using it_type = long long;
  int32_t n;
  vector<it_type> it;
  vector<long long> lz;
  const it_type FAILED_STAGE = INF;
  void init(int _){
    n = _;
    it.resize((n << 2)|1);
    lz.resize((n << 2)|1, INF); // check init lazy
  }
  it_type merge(it_type a, it_type b){
    return min(a, b);
  }
  it_type build(int32_t u, int32_t l, int32_t r, auto &a){ // 1 indexed
    if(l == r) return it[u] = a[l];
    return it[u] = merge(build(u << 1, l, ((l + r)>>1), a), build((u << 1)|1, ((l + r)>>1) + 1, r, a)); // merge stage
  }
  void lazy(int32_t u, int32_t l, int32_t r){ // lazy 
    if(lz[u] == INF) return;
    it[u] = min(it[u], lz[u]);
    if(l != r){
      lz[u << 1] = min(lz[u << 1], lz[u]);
      lz[(u << 1)|1] = min(lz[(u << 1)|1], lz[u]);
    }
    lz[u] = INF;
  }
  void update(int32_t u, int32_t l, int32_t r, int32_t L, int32_t R, int val){
    if(R < L) return;
    lazy(u, l, r);
    if(l > R || r < L) return;
    if(L <= l && r <= R){
      lz[u] = val; // lazy update 
      lazy(u, l, r);
      return;
    }
    update(u << 1, l, ((l + r)>>1), L, R, val);
    update((u << 1)|1, ((l + r)>>1) + 1, r, L, R, val);
    it[u] = merge(it[u << 1], it[(u << 1)|1]); // merge stage
  }
  it_type get(int32_t u, int32_t l, int32_t r, int32_t L, int32_t R){
    if(l > R || r < L) return FAILED_STAGE; // check for failed stage
    lazy(u, l, r);
    if(L <= l && r <= R) return it[u];
    return merge(get(u << 1, l, ((l + r)>>1), L, R), get((u << 1)|1, ((l + r)>>1) + 1, r, L, R)); // merge stage
  }
};
signed main(){
  ios_base::sync_with_stdio(0); 
  cin.tie(0);
  // freopen("FDT.txt", "r", stdin);
  int n;
  cin >> n;
  int rem = (n - 2)*(n - 2);
  vector<int> tmp(n, n - 1);
  lazy_segment_tree ver, hor;
  ver.init(n);
  ver.build(1, 1, n, tmp);
  hor.init(n);
  hor.build(1, 1, n, tmp);
  int q;
  cin >> q;
  while(q --){
    int tp, x;
    cin >> tp >> x;
    if(tp == 1){
      int lv = hor.get(1, 1, n, x, x);
      // cout << lv << endl;
      rem -= (lv - 1);
      ver.update(1, 1, n, 1, lv, x - 1);
    }
    else{
      int lv = ver.get(1, 1, n, x, x);
      // cout << lv << endl;
      rem -= (lv - 1);
      hor.update(1, 1, n, 1, lv, x - 1);
    }
  }
  cout << rem;
}

Measured memory_bytes: 29876