#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define rep(i, n) for(int i = 0; i < n; i++)
const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
  int N, Q;
  cin >> N >> Q;
  //一番手前の黒の位置
  vi down(N - 2, N - 3);
  vi right(N - 2, N - 3);
  ll n = N;
  ll ans = (n - 2) * (n - 2);
  //左斜め上の黒のみの長方形の右辺と下辺
  int R = N - 3;
  int D = N - 3;
  rep(i, Q) {
    int a, x;
    cin >> a >> x;
    x -= 2;
    if(a == 1) {
      if(x > R) {
        ans -= down.at(x) + 1;
      }
      else {
        ans -= D + 1;
        for(int j = x; j <= R; j++) {
          down.at(j) = D;
        }
        R = x - 1;
      }
    }
    else {
      if(x > D) {
        ans -= right.at(x) + 1;
      }
      else {
        ans -= R + 1;
        for(int j = x; j <= D; j++) {
          right.at(j) = R;
        }
        D = x - 1;
      }
    }
  }
  cout << ans << endl;
}