//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
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 T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

template<class T>
struct SegTree {
  using FX = function<T(T, T)>;
  int n, _n;
  FX fx;
  const T ex;
  vector<T> dat;
  SegTree(int n_, FX fx_, T ex_):fx(fx_), ex(ex_), n(1), _n(n_) {
    while(n < n_) n <<= 1;
    dat.assign((n<<1)-1, ex);
  }
  SegTree(vector<T> &v, FX fx_, T ex_):fx(fx_), ex(ex_), n(1), _n(int(v.size())) {
    while(n < _n) n <<= 1;
    dat.assign((n<<1)-1, ex);
    copy(v.begin(), v.end(), dat.begin()+n-1);
    build();
  }
  inline int chld(int k) {return (k<<1)+1;}
  inline int chrd(int k) {return (k<<1)+2;}
  void set(int i, T t) {dat[i+n-1] = t;}
  void build() {
    for(int k = n-2; k >= 0; k--) dat[k] = fx(dat[chld(k)], dat[chrd(k)]);
  }
  void update(int i, T x) {
    i += n-1;
    dat[i] = x;
    while(i) {
      i = (i-1)>>1;
      dat[i] = fx(dat[chld(i)], dat[chrd(i)]);
    }
  }
  inline T query(int a, int b) {return query(a, b, 0, 0, n);}
  T query(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return ex;
    if(a <= l && r <= b) return dat[k];
    T vl = query(a, b, chld(k), l, (l+r)>>1);
    T vr = query(a, b, chrd(k), (l+r)>>1, r);
    return fx(vl, vr);
  }
  template<class F>
  int max_right(int l, F f) {
    assert(f(ex));
    if(l == _n) return _n;
    l += n;
    T now = ex;
    do {
      while(~l&1) l >>= 1;
      if(!f(fx(now, dat[l-1]))) {
        while(l < n) {
          l <<= 1;
          if(f(fx(now, dat[l-1]))) {
            now = fx(now, dat[l++ - 1]);
          }
        }
        return l-n;
      }
      now = fx(now, dat[l++ - 1]);
    } while((l & -l) != l);
    return _n;
  }
  template<class F>
  int min_left(int r, F f) {
    assert(f(ex));
    if(r == 0) return 0;
    r += n;
    T now = ex;
    do {
      r--;
      while(r > 1 and r&1) r >>= 1;
      if(!f(fx(dat[r-1], now))) {
        while(r < n) {
          r = chld(r);
          if(f(fx(dat[r-1], now))) {
            now = fx(dat[--r], now);
          }
        }
        return r+1-n;
      }
      now = fx(dat[r-1], now);
    } while((r & -r) != r);
    return 0;
  }
  const T &operator[](int idx) const {return dat[idx+n-1];}
};

#define N 200100

//head

int n, q;
SegTree<int> segh(N, [](int a, int b)->int{return max(a, b);}, 0), segw(N, [](int a, int b)->int{return max(a, b);}, 0);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  ll ans = n-2;
  ans *= ans;
  rep(i, q) {
    int type, x;
    cin >> type >> x;
    if(type == 1) {
      int u = segh.max_right(0, [x](int i) {return i < x;});
      chmin(u, n);
      ans -= u-2;
      segw.update(x, u);
    }
    else {
      int u = segw.max_right(0, [x](int i) {return i < x;});
      chmin(u, n);
      ans -= u-2;
      segh.update(x, u);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 7288