#line 1 "main_f.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

#line 2 "/home/imperi/cp-library/lib/SegmentTree/DualSegmentTree.hpp"

#line 5 "/home/imperi/cp-library/lib/SegmentTree/DualSegmentTree.hpp"

// commutative Monoid
// type value_t
// static value_t id
// static (value_t,value_t)->value_t op

template <typename Monoid>
class DualSegmentTree {
 public:
  using value_t = typename Monoid::value_t;
  using size_t = std::size_t;

 private:
  struct Node {
    value_t val;
    std::shared_ptr<Node> left, right;
    Node(value_t val_) : val(val_), left(), right() {}
  };

  using node_ptr = std::shared_ptr<Node>;

  size_t n, n0;
  node_ptr root;

  void update(size_t a, size_t b, value_t value, const node_ptr& now, size_t l,
              size_t r) {
    if (a <= l && r <= b) {
      now->val = Monoid::op(now->val, value);
      return;
    }
    if (b <= l || r <= a) return;

    if (!now->left) now->left = std::make_shared<Node>(Monoid::id);
    if (!now->right) now->right = std::make_shared<Node>(Monoid::id);
    update(a, b, value, now->left, l, l + (r - l) / 2);
    update(a, b, value, now->right, l + (r - l) / 2, r);
  }

 public:
  DualSegmentTree(size_t n_) : n(n_), root(new Node(Monoid::id)) {
    n0 = 1;
    while (n0 < n) n0 <<= 1;
  }

  void update(size_t l, size_t r, value_t value) {
    assert(0 <= l && l <= r && r <= n);
    update(l, r, value, root, 0, n0);
  }

  value_t at(size_t i) {
    assert(0 <= i && i < n);
    node_ptr now(root);
    value_t ret = now->val;

    size_t l = 0, r = n0;
    while (r - l > 1) {
      size_t mid = l + (r - l) / 2;
      if (i < mid) {
        if (!now->left) break;
        now = now->left;
        r = mid;
      } else {
        if (!now->right) break;
        now = now->right;
        l = mid;
      }
      ret = Monoid::op(ret, now->val);
    }
    return ret;
  }
};
#line 85 "main_f.cpp"

struct Monoid{
  using value_t = i64;
  static constexpr value_t id=1e18;
  static constexpr value_t op(value_t a,value_t b){
    return std::min(a,b);
  }
};

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  i64 n,q;
  std::cin>>n>>q;

  DualSegmentTree<Monoid> row(n-2),col(n-2);
  row.update(0,n-2,n-2);
  col.update(0,n-2,n-2);

  i64 ans=0;

  while(q--){
    i64 mode,x;
    std::cin>>mode>>x;
    x-=2;
    if(mode==1){
      i64 val=col.at(x);
      ans+=val;
      row.update(0,val,x);
    }else{
      i64 val=row.at(x);
      ans+=val;
      col.update(0,val,x);
    }
  }

  std::cout<<(n-2)*(n-2)-ans<<"\n";
  
  return 0;
}


Measured memory_bytes: 21544