#include <iostream>
#include <vector>
#define rep(i, n) for (int64_t i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, Q;
  cin >> N >> Q;

  int64_t black = (N - 2) * (N - 2);
  vector<int> row(N + 1, N);
  vector<int> col(N + 1, N);
  int H = N;
  int W = N;
  rep(i, Q) {
    int t, x;
    cin >> t >> x;
    if (t == 1) {
      if (x < W) {
        for (int j = x; j < W; ++j) {
          row[j] = H;
        }
        W = x;
      }
      black -= (row[x] - 2);
    } else {
      if (x < H) {
        for (int j = x; j < H; ++j) {
          col[j] = W;
        }
        H = x;
      }
      black -= (col[x] - 2);
    }
  }
  cout << black << endl;
  return 0;
}
