#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
using ll = long long;
#define N 200004

class SegmentTree {
  const ll inf = 1e18;
  int n, n0;
  ll max_v[4*N], smax_v[4*N], max_c[4*N];

  ll ladd[4*N]; // 区間加算クエリにおけるlazy tag
  ll len[4*N];  // ノードの区間に含まれる要素の数

  ll sum_a[4*N]; // 最大値の総和
  ll sum_b[4*N]; // 非最大値の総和

  void update_node_max(int k, ll x) {
    // 最大値の総和だけ加算
    sum_a[k] += (x - max_v[k]) * max_c[k];

    max_v[k] = x;
  }

  void addall(int k, ll x) {
    max_v[k] += x; smax_v[k] += x;

    // 最大値の総和・非最大値の総和それぞれに加算
    sum_a[k] += x * max_c[k];
    sum_b[k] += x * (len[k] - max_c[k]);

    ladd[k] += x;
  }

  void push(int k) {
    if(ladd[k]) {
      addall(2*k+1, ladd[k]);
      addall(2*k+2, ladd[k]);
      ladd[k] = 0;
    }

    if(max_v[k] < max_v[2*k+1]) {
      update_node_max(2*k+1, max_v[k]);
    }
    if(max_v[k] < max_v[2*k+2]) {
      update_node_max(2*k+2, max_v[k]);
    }
  }

  void update(int k) {
    // 最大値の総和と非最大値の総和を子ノードから更新
    sum_b[k] = sum_b[2*k+1] + sum_b[2*k+2];

    if(max_v[2*k+1] < max_v[2*k+2]) {
      max_v[k] = max_v[2*k+2];
      max_c[k] = max_c[2*k+2];
      smax_v[k] = max(max_v[2*k+1], smax_v[2*k+2]);

      sum_a[k] = sum_a[2*k+2];
      sum_b[k] += sum_a[2*k+1];
    } else if(max_v[2*k+1] > max_v[2*k+2]) {
      max_v[k] = max_v[2*k+1];
      max_c[k] = max_c[2*k+1];
      smax_v[k] = max(smax_v[2*k+1], max_v[2*k+2]);

      sum_a[k] = sum_a[2*k+1];
      sum_b[k] += sum_a[2*k+2];
    } else {
      max_v[k] = max_v[2*k+1];
      max_c[k] = max_c[2*k+1] + max_c[2*k+2];
      smax_v[k] = max(smax_v[2*k+1], smax_v[2*k+2]);

      sum_a[k] = sum_a[2*k+1] + sum_a[2*k+2];
    }
  }

  void _update_min(ll x, int a, int b, int k, int l, int r) {
    if(b <= l || r <= a || max_v[k] <= x) {
      return;
    }
    if(a <= l && r <= b && smax_v[k] < x) {
      update_node_max(k, x);
      return;
    }

    push(k);
    _update_min(x, a, b, 2*k+1, l, (l+r)/2);
    _update_min(x, a, b, 2*k+2, (l+r)/2, r);
    update(k);
  }

  ll _query_max(int a, int b, int k, int l, int r) {
    if(b <= l || r <= a) {
      return 0;
    }
    if(a <= l && r <= b) {
      return max_v[k];
    }
    push(k);
    ll lv = _query_max(a, b, 2*k+1, l, (l+r)/2);
    ll rv = _query_max(a, b, 2*k+2, (l+r)/2, r);
    return max(lv, rv);
  }

  ll _query_sum(int a, int b, int k, int l, int r) {
    if(b <= l || r <= a) {
      return 0;
    }
    if(a <= l && r <= b) {
      // 最大値の総和・非最大値の総和を合わせる
      return sum_a[k] + sum_b[k];
    }
    push(k);
    ll lv = _query_sum(a, b, 2*k+1, l, (l+r)/2);
    ll rv = _query_sum(a, b, 2*k+2, (l+r)/2, r);
    return lv + rv;
  }

public:
  SegmentTree(int n, ll *a) : n(n) {
    n0 = 1;
    while(n0 < n) n0 <<= 1;

    len[0] = n0;
    for(int i=0; i<n0-1; ++i) len[2*i+1] = len[2*i+2] = (len[i] >> 1);

    for(int i=0; i<n; ++i) {
      max_v[n0-1+i] = sum_a[n0-1+i] = a[i];
      smax_v[n0-1+i] = -inf; sum_b[n0-1+i] = 0;
      max_c[n0-1+i] = 1;
    }

    for(int i=n; i<n0; ++i) {
      max_v[n0-1+i] = smax_v[n0-1+i] = -inf;
      sum_a[n0-1+i] = sum_b[n0-1+i] = max_c[n0-1+i] = 0;
    }
    for(int i=n0-2; i>=0; i--) update(i);
  }

  void update_min(int a, int b, ll x) {
    return _update_min(x, a, b, 0, 0, n0);
  }

  ll query_max(int a, int b) {
    return _query_max(a, b, 0, 0, n0);
  }

  ll query_sum(int a, int b) {
    return _query_sum(a, b, 0, 0, n0);
  }
};

ll n, q;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> n >> q;
    ll a[n-2];
    rep(i, n-2) a[i] = n-2;
    SegmentTree st1(n-2, a), st2(n-2, a);
    //st1.update_min(0, n-2, n-2);
    //st2.update_min(0, n-2, n-2);
    //rep(i, n-2) {
        //st1.update_node_max(i, n-2);
        //st2.update_node_max(i, n-2);
    //}
    
    ll ans = (n-2)*(n-2);
    while (q--) {
        ll t, x; cin >> t >> x;
        x -= 2;
        if (t==1) {
            ll er = st1.query_sum(x, x+1);
            //cout << er << endl;
            ans -= er;
            st2.update_min(0, er, x);
        }
        else {
            ll er = st2.query_sum(x, x+1);
            //cout << er << endl;
            ans -= er;
            st1.update_min(0, er, x);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 54440