#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  200005

// segment tree for minimum
class segtree
{
public:
    vi a,seg,lazy;
    segtree(ll n)
    {
        a.resize(200005,n);
        seg.resize(800005);
        lazy.resize(800005);
    }
    void build(ll n,ll l,ll r)
    {
        if(l==r)
        {
            seg[n]=a[l];
            return;
        }
        ll m=(l+r)>>1;
        build(2*n,l,m);
        build(2*n+1,m+1,r);
        seg[n]=min(seg[2*n],seg[2*n+1]);
    }
    void push(ll n)
    {
        if(lazy[n]!=0)
        {
            if(lazy[2*n]==0)
                lazy[2*n]=lazy[n];
            else
                lazy[2*n]=min(lazy[2*n],lazy[n]);
            if(lazy[2*n+1]==0)
                lazy[2*n+1]=lazy[n];
            else
                lazy[2*n+1]=min(lazy[2*n+1],lazy[n]);
            seg[2*n]=min(seg[2*n],lazy[n]);
            seg[2*n+1]=min(seg[2*n+1],lazy[n]);
            lazy[n]=0;
        }
    }
    void update(ll n,ll l,ll r,ll low,ll high,ll val)
    {
        if(l>high||low>r)
            return;
        if(low<=l&&r<=high)
        {
            seg[n]=min(seg[n],val);
            if(lazy[n]==0)
                lazy[n]=val;
            else
            {
                lazy[n]=min(lazy[n],val);
            }
            return;
        }
        push(n);
        ll mid=(l+r)>>1;
        update(2*n,l,mid,low,high,val);
        update(2*n+1,mid+1,r,low,high,val);
        seg[n]=min(seg[2*n],seg[2*n+1]);
    }
    ll query(ll n,ll l,ll r,ll idx)
    {
        if(l==r)
            return seg[n];
        ll mid=(l+r)>>1;
        push(n);
        if(idx<=mid)
            return query(2*n,l,mid,idx);
        else
            return query(2*n+1,mid+1,r,idx);
    }
};
void solve()
{
    ll n,q;
    cin>>n>>q;
    segtree segx(n),segy(n);
    segx.build(1,1,n);
    segy.build(1,1,n);
    ll ans=2*n-1;
    ll total=(n-2)*(n-2)+2*n-1+q;
    while(q--)
    {
        ll x,y;
        cin>>x>>y;
        if(x==1)
        {
            ll z=segy.query(1,1,n,y)-1;
            ans+=z;
            segx.update(1,1,n,1,z,y);
        }
        else
        {
            ll z=segx.query(1,1,n,y)-1;
            ans+=z;
            segy.update(1,1,n,1,z,y);
        }
    }
    cout<<total-ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 31472