#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define C continue;
#define R return

#define ull unsigned long long int
#define ll long long int
#define ld long double
#define D double

#define V vector
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vb vector<bool>
#define vd vector<D>
#define vll vector<ll>
#define vull vector<ull>
#define vld vector<ld>

#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vvc vector<vector<char>>
#define vvll vector<vector<ll>>
#define vvd vector<vector<D>>
#define vvld vector<vector<ld>>

#define P pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define pld pair<ld, ld>
#define F first
#define S second

#define vpld vector<pld>
#define vpii vector<pii>
#define vpll vector<pll>

#define vvpii vector<vector<pii>>
#define vvpll vector<vector<pll>>

#define PQ(type) priority_queue<type>
#define PQD(type) priority_queue<type, vector<type>, greater<type>>

#define mii map<int, int>
#define mll map<ll, ll>
#define mci map<char, int>
#define msi map<string, int>
#define mis map<int, string>

#define umii unordered_map<int, int>
#define umll unordered_map<ll, ll>
#define umci unordered_map<char, int>
#define umsi unordered_map<string, int>
#define umis unordered_map<int, string>

//IO
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie();                        \
    cout.tie();
#define read freopen("input.txt", "r", stdin);
#define write freopen("output.txt", "w", stdout);
#define in1(x, n) f(i, n) cin >> x[i];
#define in2(x, n, m) f(i, n) f(j, m) cin >> x[i][j];
#define inp(x, n) f(i, n) cin >> x[i].F >> x[i].S;
#define out1(x, n)               \
    f(i, n) cout << x[i] << " "; \
    cout << "\n";
#define out2(x, n, m)                   \
    f(i, n)                             \
    {                                   \
        f(j, m) cout << x[i][j] << " "; \
        cout << "\n";                   \
    }
#define outp(x, n) f(i, n) cout << x[i].F << " " << x[i].S << "\n";
#define pp(n) printf("%.10Lf", n);
#define prdbl(val, precise) cout << fixed << setprecision(precise) << val << "\n";
#define dbg1(x) cout << " > " << #x << " = " << x << "\n";
#define dbg2(x, y) cout << " < " << #x << " = " << x << ", " << #y << " = " << y << endl;
#define line cout << "\n";

#define init(x, val) memset(x, val, sizeof(x)) //can be 0 or -1
#define mem(x, val) memset(x, val, sizeof(x))  //can be 0 or -1 only

//loops
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define loop(i, a, b) for (ll i = a; i <= b; i++)
#define loopr(i, a, b) for (ll i = a; i >= b; i--)
#define loops(i, a, b, step) for (ll i = a; i < b; i += step)
#define looprs(i, a, b, step) for (ll i = a; i >= b; i -= step)
#define f(i, n) for (ll i = 0; i < n; i++)
#define ff(i, n) for (ll i = 1; i <= n; i++)
#define fr(i, n) for (ll i = n - 1; i >= 0; i--)
#define fir(x, y) f(ll i = min(x, y); i <= max(x, y); i++)
#define firr(x, y) f(ll i = max(x, y); i <= min(x, y); i++)
#define inrange(i, a, b) ((i >= min(a, b)) && (i <= max(a, b)))

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define bgn(x) ((x).begin())
#define sz(x) ((x).size())
#define mxe(a) *(max_element(all(a))
#define mne(a) *(min_element(all(a))
#define lb lower_bound
#define ub upper_bound
#define rev reverse

#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define I insert

#define count_1(n) __builtin_popcountll(n)
#define sqr(x) ((x) * (x))
#define dist(a, b, p, q) sqrt((p - a) * (p - a) + (q - b) * (q - b))

#define mod1 1000000007
#define mod2 998244353

//functions

void yes()
{
    cout << "YES";
    //cout << "\n";
}

void no()
{
    cout << "NO";
    //cout << "\n";
}

ll pmod(ll a, ll mod = mod1) { return ((a) % mod + mod) % mod; }

ll cel(ll x1, ll y1) //not for negative x1
{
    if ((x1) <= 0)
    {
        return (x1) / (y1);
    }
    return (((x1) / (y1)) + (((x1) % (y1)) != 0));
}

bool isprime(ll n)
{
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0)
            return false;
    return true;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    return ((a / gcd(a, b)) * b);
}

long long bp(long long a, long long b)
{
    long long res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

long long bpm(long long a, long long b, long long m = mod1)
{
    if (a >= m)
        a %= m;
    long long res = 1;
    while (b > 0)
    {
        if (b & 1)
            res *= a;
        if (res >= m)
            res %= m;
        a *= a;
        if (a >= m)
            a %= m;
        b >>= 1;
    }
    if (res >= m)
        res %= m;
    return res;
}

//constants

string vow = "aeiou";

const int dr4[] = {-1, 0, 1, 0};
const int dc4[] = {0, 1, 0, -1};

const int drk[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dck[] = {0, 1, 0, -1, -1, 1, -1, 1};

const int drh[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dch[] = {1, -1, 2, -2, 2, -2, 1, -1};

const ll maxn = 2e5 + 5;
const ll inf = 1e9;
const ld PI = acos(-1);
const int imin = INT_MIN;
const int imax = INT_MAX;
const ll lmax = LLONG_MAX;
const ll lmin = LLONG_MIN;
const ld dmin = DBL_MIN;
const ld dmax = DBL_MAX;

struct row{
    int seg[4 * maxn];
    int lazy[4 * maxn];
}rr;
struct col{
    int seg[4 * maxn];
    int lazy[4 * maxn];
}cc;

ll queryr(int l,int r,int v=0,int bg=0,int ed=maxn-1){
    if(cc.lazy[v]!=INT_MAX){
        if(bg!=ed){
            cc.lazy[2 * v + 1] = min(cc.lazy[2 * v + 1], cc.lazy[v]);
            cc.lazy[2 * v + 2] = min(cc.lazy[2 * v + 2], cc.lazy[v]);
        }
        cc.seg[v]=min(cc.seg[v],cc.lazy[v]);
        cc.lazy[v] = INT_MAX;
    }
    if(r<bg || l>ed)
        return INT_MAX;
        if(bg==ed)
            return cc.seg[v];
    int md = bg + ed >> 1;
    int ql = queryr(l, r, 2 * v + 1, bg, md);
    int qr = queryr(l, r, 2 * v + 2, md + 1, ed);
    return min(ql, qr);
}
// ll queryr(int l, int r, int v = 0, int bg = 0, int ed = maxn - 1)
// {
//     if (cc.lazy[v] != INT_MAX)
//     {
//         if (bg != ed)
//         {
//             cc.lazy[2 * v + 1] = min(cc.lazy[2 * v + 1], cc.lazy[v]);
//             cc.lazy[2 * v + 2] = min(cc.lazy[2 * v + 2], cc.lazy[v]);
//         }
//         cc.seg[v] = min(cc.seg[v], cc.lazy[v]);
//         cc.lazy[v] = INT_MAX;
//     }
//     if (r < bg || l > ed)
//         return INT_MAX;
//     if (bg == ed)
//         return cc.seg[v];
//     int md = bg + ed >> 1;
//     ll ql = queryr(l, r, 2 * v + 1, bg, md);
//     ll qr = queryr(l, r, 2 * v + 2, md + 1, ed);
//     return min(ql, qr);
// }

void updater(int l,int r,int val,int v=0,int bg=0,int ed=maxn-1){
     if(rr.lazy[v]!=INT_MAX){
         if (bg != ed)
         {
             rr.lazy[2 * v + 1] = min(rr.lazy[2 * v + 1], rr.lazy[v]);
             rr.lazy[2 * v + 2] = min(rr.lazy[2 * v + 2], rr.lazy[v]);
         }
         rr.seg[v] = min(rr.seg[v], rr.lazy[v]);
         rr.lazy[v] = INT_MAX;
     }
     if (r < bg || l > ed)
         return;
     if (l<=bg && ed<=r){
         rr.lazy[v] = min(rr.lazy[v], val);
         return;
     }
      int md=bg+ed>>1;
      updater(l, r, val, 2 * v + 1, bg, md);
      updater(l, r, val, 2 * v + 2, md + 1, ed);
}

void updatec(int l,int r,int val,int v=0,int bg=0,int ed=maxn-1){
     if(cc.lazy[v]!=INT_MAX){
         if (bg != ed)
         {
             cc.lazy[2 * v + 1] = min(cc.lazy[2 * v + 1], cc.lazy[v]);
             cc.lazy[2 * v + 2] = min(cc.lazy[2 * v + 2], cc.lazy[v]);
         }
         cc.seg[v] = min(cc.seg[v], cc.lazy[v]);
         cc.lazy[v] = INT_MAX;
     }
     if (r < bg || l > ed)
         return;
     if (l<=bg && ed<=r){
         cc.lazy[v] = min(cc.lazy[v], val);
         return;
     }
     int md = bg + ed >> 1;
     updatec(l, r, val, 2 * v + 1, bg, md);
     updatec(l, r, val, 2 * v + 2, md + 1, ed);
}

ll queryc(int l, int r, int v = 0, int bg = 0, int ed = maxn - 1)
{
    if (rr.lazy[v] != INT_MAX)
    {
        if (bg != ed)
        {
            rr.lazy[2 * v + 1] = min(rr.lazy[2 * v + 1], rr.lazy[v]);
            rr.lazy[2 * v + 2] = min(rr.lazy[2 * v + 2], rr.lazy[v]);
        }
        rr.seg[v] = min(rr.seg[v], rr.lazy[v]);
        rr.lazy[v] = INT_MAX;
    }
    if (r < bg || l > ed)
        return INT_MAX;
    if (bg == ed)
        return rr.seg[v];
    int md = bg + ed >> 1;
    ll ql = queryc(l, r, 2 * v + 1, bg, md);
    ll qr = queryc(l, r, 2 * v + 2, md + 1, ed);
    return min(ql, qr);
}

void solve(int tc)
{
  ll n,q;
  cin >> n >> q;
    for (int i = 0;i<4*maxn;i++){
      rr.seg[i] = n;
      cc.seg[i] = n;
      rr.lazy[i] = INT_MAX;
      cc.lazy[i] = INT_MAX;
  }

  ll cnt = (n - 2LL) * (n - 2LL);
  while (q--)
  {
      int qt;
      cin >> qt;

      if (qt == 1)
      {
          int x;
          cin >> x;
          ll mr = queryr(x, x);
         // cout << mr << "\n";
          cnt -= (mr - 2);
          if(mr>=1){
              updater(1, mr-1, x);
          }
      }
      else
      {
          int x;
          cin>>x;
          ll mc = queryc(x, x);
          //cout << mc << "\n";
          cnt -= (mc - 2);
          if(mc>=1){
              updatec(1, mc-1, x);
          }

      }
  }
  cout << cnt;
}


int main()
{

    //read

    //write
    fast;
    int t = 1;
    //cin >> t;
    loop(i, 1, t)
    {

        solve(i);
        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 16116