#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 2e5+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
ll n,q;
int t[4*MAXN];
int p[4*MAXN];
void push(int v,int vl,int vr)
{
    if (p[v]==INF)
        return;
    t[v]=min(t[v],p[v]);
    if (vl!=vr)
    {
        p[2*v+1]=min(p[2*v+1],p[v]);
        p[2*v+2]=min(p[2*v+2],p[v]);
    }
    p[v]=INF;
}
void build(int v,int vl,int vr)
{
    if (vl==vr)
    {
        t[v]=n-1;
        return;
    }
    int mid=((vl+vr)>>1);
    build(2*v+1,vl,mid);
    build(2*v+2,mid+1,vr);
    t[v]=min(t[2*v+1],t[2*v+2]);
}
void update(int v,int vl,int vr,int l,int r,int x)
{
    push(v,vl,vr);
    if (vr<l||vl>r)
        return;
    if (l<=vl&&vr<=r)
    {
        p[v]=min(p[v],x);
        push(v,vl,vr);
        return;
    }
    int mid=((vl+vr)>>1);
    update(2*v+1,vl,mid,l,r,x);
    update(2*v+2,mid+1,vr,l,r,x);
    t[v]=min(t[2*v+1],t[2*v+2]);
}
int query(int v,int vl,int vr,int l,int r)
{
    push(v,vl,vr);
    if (vl>r||vr<l)
        return INF;
    if (l<=vl&&vr<=r)
    {
        return t[v];
    }
    int mid=((vl+vr)>>1);
    return min(query(2*v+1,vl,mid,l,r),query(2*v+2,mid+1,vr,l,r));
}
int t1[4*MAXN];
int p1[4*MAXN];
void push1(int v,int vl,int vr)
{
    if (p1[v]==INF)
        return;
    t1[v]=min(t1[v],p1[v]);
    if (vl!=vr)
    {
        p1[2*v+1]=min(p1[2*v+1],p1[v]);
        p1[2*v+2]=min(p1[2*v+2],p1[v]);
    }
    p1[v]=INF;
}
void build1(int v,int vl,int vr)
{
    if (vl==vr)
    {
        t1[v]=n-1;
        return;
    }
    int mid=((vl+vr)>>1);
    build1(2*v+1,vl,mid);
    build1(2*v+2,mid+1,vr);
    t1[v]=min(t1[2*v+1],t1[2*v+2]);
}
void update1(int v,int vl,int vr,int l,int r,int x)
{
    push1(v,vl,vr);
    if (vr<l||vl>r)
        return;
    if (l<=vl&&vr<=r)
    {
        p1[v]=min(p1[v],x);
        push1(v,vl,vr);
        return;
    }
    int mid=((vl+vr)>>1);
    update1(2*v+1,vl,mid,l,r,x);
    update1(2*v+2,mid+1,vr,l,r,x);
    t1[v]=min(t1[2*v+1],t1[2*v+2]);
}
int query1(int v,int vl,int vr,int l,int r)
{
    push1(v,vl,vr);
    if (vl>r||vr<l)
        return INF;
    if (l<=vl&&vr<=r)
    {
        return t1[v];
    }
    int mid=((vl+vr)>>1);
    return min(query1(2*v+1,vl,mid,l,r),query1(2*v+2,mid+1,vr,l,r));
}
void solve()
{
    cin>>n>>q;
    ll ans=(n-2)*(n-2);
    for (int i=0;i<4*n;i++)
        p[i]=INF,p1[i]=INF;
    build(0,0,n-1);
    build1(0,0,n-1);
//    for (int i=0;i<n;i++)
//        cout<<query1(0,0,n-1,i,i)<<" ";
//    cout<<'\n';
    while (q--)
    {
        int type;
        cin>>type;
        int x;
        cin>>x;
        x--;
        if (type==1)
        {
            int what=query(0,0,n-1,x,x);
            ans-=max(0,what-1);
            if (what-1>=0)
            update1(0,0,n-1,0,what-1,x);
        }
        else
        {
            int what=query1(0,0,n-1,x,x);
            ans-=max(0,what-1);
            if (what-1>=0)
                update(0,0,n-1,0,what-1,x);
        }
    }
    cout<<ans<<'\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int _t;
    _t=1;
//    cin>>_t;
    while (_t--)
        solve();
    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 13968