#include <bits/stdc++.h>
using namespace std;

int main(){
int n, q;
    cin >> n >> q;
    vector<int> ve(n), ho(n);
    auto ans = long(n - 2) * (n - 2);
    for (int vl = n, hl = n; q--;) {
      int tp, x;
      cin >> tp >> x;
      if (tp == 1) {
        if (x < vl) {
          while (vl > x) {
            ve[--vl] = hl;
          }
          ans -= hl - 2;
        } else {
          ans -= ve[x] - 2;
        }
      } else {
        if (x < hl) {
          while (hl > x) {
            ho[--hl] = vl;
          }
          ans -= vl - 2;
        } else {
          ans -= ho[x] - 2;
        }
      }
    }
    cout << ans << endl;
}
