/*                                                                                                    
                                             `-:://:::-                                             
                                           `//:-------:/:`                                          
                                          .+:--.......--:+`                                         
                                         `+:--..`````..--//`                                        
                                         .o:--..`` ``..--:o`                                        
                                         .o:--...```..---+/`                                        
                                       `/y+o/---....---:+o.                                         
                                   `...````-os+/:---:/+o/--.`                                       
              `-/+++++/:.      `...`       :h+d+oooo+/+-`   ...                                     
            `/++//:::://++-`....`         -.`//````````:`     `..`                                  
           `o+/::------://o/`           `-` -.          -`       `..`                               
  `....o+:-++/:--.```..-://s.        `-`  .-              -`          `-o: .-//::::/:-`             
          `:s+/:--....-::/+s-`      .-   `-                -`           -///:--------:/:`           
            .:ooo+++++osso-`    `.:-...`/` ./::-------:/:`   -`         :+--..``````.--:+:...-+:-`  
             `.-/+++++/+-.-`    -.   ``:so:/:--.......--:+`  `-```````o+/+--..`````..--:o/-..:s+:.  
                 ```````:``.. `-`     -` `+:--..`````..--/+-.../.`````..-o:--.......---/o.    `     
                        `:  `:-      -.  .o:--..`` ``..--:o`   `-`      `:o+:--------:+o-`          
                         `-`-...    ..   .o/--...```..--:+/`    `-`     `oy/so/////++o/.`           
                          -/`  `-` `- ``+s/o/:---...---:++.      `-`   .-../d://///:-.`             
                `.---..``-..-    .-/..`````-oo+/:::::/+o+-        `-``-`  `-.  ````                 
             `:++++/+++++-  ..``.-/:`      /y-:/++o++/:.`..`       ./.   `-                         
            -++/::::::://+/..:-``:` ..   `-.`  ```.```    `..`   `..`-` `-                          
       ``  -o//:--....-::/++` -.-`   `-`.-`                 `..`..`  `-.-                           
  -----ss+:++/:--.```..-://s.  /.     `::                    `-:.     ./`                           
  `````/:..+o/::-..``.--:/+s. ..-`   `-``-`                 ..` `-`  `-`-`                          
          `-s+/::-----::/+oo---``-` ..    .:-    ```      .-`     .-.-  `-`                         
           `:oo+//::://+os/..:`..-/:`      :y.-:::::::.`.-`        ./-`  `-`                        
            `./+oooooooo+/.`-    .-:...`.. .//:-------://`        `- `..` `:.                       
              ``.-::::-.``-/`  `-` `-  `oo:+:--.......--:/`      `-    `.:--h.``..```               
                          -.-`.-    .-   `+:--..`````..--//`    `-       /s-//::::::::.             
                         -` `/-      ..  .o:--..`` ``..--:o.```.-        `//:--------://`           
                        -` .-`.-`     -.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+`          
                       ..`-.   `-.   ``:os:o/:---...---:++.  `-     ``///+:-..``````.--:+-````-.`   
              `.:///////.-`      .:-..` -``-+o+/:::::/+o/.  `-         `:+:-..`````..--:o/:--/ys+-  
            `-++///////+o/. ``....`-.    :` `.:++++++/:.`  .-           -o/---......---/o.   `.`    
           `++//:-----::/+o:..`     .-`   :    ```````    .-           `+so+:--------:++-`          
  `````:-``:o/::-..`..--:/+o`         -.  `-             .-          `../../+o+////+o+:.`           
  -----syo/o+/:--.```..-://s.          .-` `-           .-        `...     ``-:////:-``             
       .` `/s//:--....-::/+s.            -. `-`        .-       `..`                                
           .+o+/:::--:://+s/-..`          .::+y  ```  .-     `..`                                   
            ./oo++////+oso-`   `....       :y-+:::::::/`   ...                                      
             `.:+oooooo/-`         `....-. .//:-------:/:-.`                                        
                ``...``                 /+:+:--.......--:+`                                         
                                         `+:--..`````..--//`                                        
                                         .o:--..`` ``..--:o`                                        
                                         .+/--...```..--:+/`                                        
                                         `-o/:---...---:++.                                         
                                          `-+o+/:---:/+o/.                                          
                                            `.:+oooo+/-.`                                           
                                               ``````                                               
*/
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")
// #pragma GCC optimize("branch-target-load-optimize")
// #pragma GCC optimize("branch-target-load-optimize2")
// #pragma GCC optimize("btr-bb-exclusive")
// #pragma comment(linker, "/STACK:367077216")
#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
//#define endl '\n'
#define all(x) x.begin(), x.end()
#define int long  long
#define mk(a, b) make_pair(a, b)
 
using namespace std;
      
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<ll> > vvll;
typedef vector<char> vc;
      
const int inf = 1e9 + 228;
const ll infll = 1e18;
const ll MOD = 1e9 + 7;
//static const int maxn = 1e6 + 228;
const ld eps = 1e-5;
const int K = 31;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1<<18);
const ld PI = 3.1415926535;
     
void fast_io(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("a.in", "r", stdin);
  // freopen("digit.out", "w", stdout);
}

const int maxn = 2e5 + 228;
int t[maxn*4];
int cnt[maxn*4];

void push(int v, int l, int r){
  if(cnt[v] != inf){
    t[v] = min(cnt[v], t[v]);
    if(l!=r){
      cnt[v*2] = min(cnt[v*2], cnt[v]);
      cnt[v*2+1] = min(cnt[v*2+1], cnt[v]);
    }
    cnt[v] = inf;
  }
}

void upd(int v, int l, int r, int ql, int qr, int k){
  push(v, l, r);
  if(ql<=l && r<=qr){
    cnt[v] = min(cnt[v], k);
    push(v, l, r);
  } else if(l>qr || ql>r){
    return;
  } else{
    push(v, l, r);
    int mid = (l+r)/2;
    upd(v*2, l, mid, ql, qr, k);
    upd(v*2+1, mid+1, r, ql, qr, k);
    t[v] = min(t[v*2], t[v*2+1]);
  }
}

int get(int v, int l, int r, int ql, int qr){
  push(v, l, r);
  if(ql<=l && r<=qr){
    return t[v];
  } else if(l>qr || ql>r){
    return inf;
  } else{
    int mid = (l+r)/2;
    return min(get(v*2, l, mid, ql, qr), get(v*2+1, mid+1, r, ql, qr));
  }
}

int t2[maxn*4];
int cnt2[maxn*4];

void push2(int v, int l, int r){
  if(cnt2[v] != inf){
    t2[v] = min(cnt2[v], t2[v]);
    if(l!=r){
      cnt2[v*2] = min(cnt2[v*2], cnt2[v]);
      cnt2[v*2+1] = min(cnt2[v*2+1], cnt2[v]);
    }
    cnt2[v] = inf;
  }
}

void upd2(int v, int l, int r, int ql, int qr, int k){
  push2(v, l, r);
  if(ql<=l && r<=qr){
    cnt2[v] = min(cnt2[v], k);
    push2(v, l, r);
  } else if(l>qr || ql>r){
    return;
  } else{
    push2(v, l, r);
    int mid = (l+r)/2;
    upd2(v*2, l, mid, ql, qr, k);
    upd2(v*2+1, mid+1, r, ql, qr, k);
    t2[v] = min(t2[v*2], t2[v*2+1]);
  }
}

int get2(int v, int l, int r, int ql, int qr){
  push2(v, l, r);
  if(ql<=l && r<=qr){
    return t2[v];
  } else if(l>qr || ql>r){
    return inf;
  } else{
    int mid = (l+r)/2;
    return min(get2(v*2, l, mid, ql, qr), get2(v*2+1, mid+1, r, ql, qr));
  }
}

void solve(){ 
  int n, q;
  cin >> n >> q;
  int ans = (n-2) * (n-2);
  for(int &i:t)
    i = n;
  for(int &i:t2)
    i = n;
  for(int &i:cnt)
    i = inf;
  for(int &i:cnt2)
    i = inf;
  for(int i=0; i<q; i++){
    int t, a;
    cin >> t >> a;
    if(t==1){
      int cur = get(1, 0, maxn-1, a, a);
      // cout << cur << endl;
      ans -= cur-2;
      upd2(1, 0, maxn-1, 1, cur, a);
    } else{
      int cur = get2(1, 0, maxn-1, a, a);
      ans -= cur-2;
      upd(1, 0, maxn-1, 1, cur, a);
    }
  }
  cout << ans << endl;
}

signed main(){
    fast_io();
    srand(time(NULL));
    // cout << fixed << setprecision(3);
    int q = 1;
    // cin >> q;
    while(q--)
        solve();
}

Measured memory_bytes: 28664