#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n, q;
  cin >> n >> q;
  
  vector<ll> a(n, n-2), b(n, n-2);

  ll ans = (n-2)*(n-2);

  ll x = n-1, y = n-1;
  for (ll i = 0; i < q; i++){
    ll c, d;
    cin >> c >> d;

    d--;
    
    if (c == 1){
      if (x < d){
        ans -= b[d] - 1;
      }
      else {
        for (ll i = d + 1; i < x; i++){
          b[i] = y;
        }

        x = d;
        ans -= y - 1;
      }
    }
    else {
      if (y < d){
        ans -= a[d] - 1;
      }
      else {
        for (ll i = d + 1; i < y; i++){
          a[i] = x;
        }

        y = d;
        ans -= x - 1;
      }
    }
  }

  cout << ans << endl;
  

  return 0;
}
