#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;
int st[4*N],lazy[4*N];
int st1[4*N+1];int lazy1[4*N];
void update(int i,int l,int r,int qs,int qe,int x)
{
    if(lazy[i]!= INF)
    {
        st[i]=min(st[i],lazy[i]);
        if(l!=r)
        {
            lazy[2*i+1]=min(lazy[2*i+1],lazy[i]);
            lazy[2*i+2]=min(lazy[2*i+2],lazy[i]);
        }
        lazy[i]=INF;
    }
    if(qs>r||qe<l)
        return;
    if(qs<=l&&qe>=r)
    {
        st[i]=min(st[i],x);
        if(l!=r)
        {
            lazy[2*i+1]=min(x,lazy[2*i+1]);
            lazy[2*i+2]=min(x,lazy[2*i+2]);
        }
        return;
    }
    int m=(l+r)/2;
    update(2*i+1,l,m,qs,qe,x);
    update(2*i+2,m+1,r,qs,qe,x);
    st[i]=min(st[2*i+1],st[2*i+2]);
}
int query(int i,int l,int r,int qs,int qe)
{
    if(lazy[i]!= INF)
    {
        st[i]=min(st[i],lazy[i]);
        if(l!=r)
        {
            lazy[2*i+1]=min(lazy[2*i+1],lazy[i]);
            lazy[2*i+2]=min(lazy[2*i+2],lazy[i]);
        }
        lazy[i]=INF;
    }
    if(qs>r||qe<l)
        return INF;
    if(qs<=l&&qe>=r)
        return st[i];
    int m=(l+r)/2;
    return min(query(2*i+1,l,m,qs,qe),query(2*i+2,m+1,r,qs,qe));
}

void update1(int i,int l,int r,int qs,int qe,int x)
{
    if(lazy1[i]!= INF)
    {
        st1[i]=min(st1[i],lazy1[i]);
        if(l!=r)
        {
            lazy1[2*i+1]=min(lazy1[2*i+1],lazy1[i]);
            lazy1[2*i+2]=min(lazy1[2*i+2],lazy1[i]);
        }
        lazy1[i]=INF;
    }
    if(qs>r||qe<l)
        return;
    if(qs<=l&&qe>=r)
    {
        st1[i]=min(st1[i],x);
        if(l!=r)
        {
            lazy1[2*i+1]=min(x,lazy1[2*i+1]);
            lazy1[2*i+2]=min(x,lazy1[2*i+2]);
        }
        return;
    }
    int m=(l+r)/2;
    update1(2*i+1,l,m,qs,qe,x);
    update1(2*i+2,m+1,r,qs,qe,x);
    st1[i]=min(st1[2*i+1],st1[2*i+2]);
}
int query1(int i,int l,int r,int qs,int qe)
{
    if(lazy1[i]!= INF)
    {
        st1[i]=min(st1[i],lazy1[i]);
        if(l!=r)
        {
            lazy1[2*i+1]=min(lazy1[2*i+1],lazy1[i]);
            lazy1[2*i+2]=min(lazy1[2*i+2],lazy1[i]);
        }
        lazy1[i]=INF;
    }
    if(qs>r||qe<l)
        return INF;
    if(qs<=l&&qe>=r)
        return st1[i];
    int m=(l+r)/2;
    return min(query1(2*i+1,l,m,qs,qe),query1(2*i+2,m+1,r,qs,qe));
}




void solve()
{
    int n,q;
    cin>>n>>q;
    for(int i=0;i<=4*N;i++)
    {
        lazy[i]=lazy1[i]=INF;
        st[i]=st1[i]=n;
    }
    int t,ans=(n-2)*(n-2);int x;
    map<pair<int,int>,int>mp;
    while(q--)
    {
        cin>>t;
        if(t==1)
        {
            cin>>x;
            if(mp.find(m1(t,x))!=mp.end())
               continue;
            mp[m1(t,x)]=1;
            int rw=query(0,0,n,x,x);
            ans-=(max((int)0,rw-2));
            update1(0,0,n,1,rw,x);
        }
        else
        {
            cin>>x;
            if(mp.find(m1(t,x))!=mp.end())
            {
                continue;
            }
            mp[m1(t,x)]=1;
            int cl=query1(0,0,n,x,x);
            ans-=(max((int)0,cl-2));
            update(0,0,n,1,cl,x);
        }
    }
    cout<<ans<<endl;
    
    
    
        
    
    
}

int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}



Measured memory_bytes: 41112