#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define sd(x) scanf("%lld",&x)
#define inf 1000000000000000000
#define pll pair<ll,ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bits(x) __builtin_popcountll(x)
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


inline ll GCD(ll x, ll y) {
    if(x<y) swap(x,y);
    if(x==0) return y;
    if(y==0) return x;
    return GCD(x%y,y);
}

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}

ll power(ll x, ll n, ll mod) {
    ll res = 1;
    x %= mod;
    while(n) {
        if(n&1) {
            res = ((res*x)%mod+mod)%mod;
        }
        x = ((x*x)%mod+mod)%mod;
        n>>=1;
    }

    return res;
}

const int MAXN = 2e5+5;

ll N;
ll trow[4*MAXN],tcol[4*MAXN];

void setup() {
    fill_n(trow,4*MAXN,N-1);
    fill_n(tcol,4*MAXN,N-1);
}

void update(ll node, ll start, ll end, ll l, ll r, ll val, ll kon) { // kon=0-row
    if(start>end || l>end || r<start) return;

    if(l<=start&&end<=r) {
        if(!kon) {
            trow[node] = min(trow[node],val);
        } else {
            tcol[node] = min(tcol[node],val);
        }
        return;
    }

    ll mid = (start+end)/2;

    if(l<=mid) update(2*node,start,mid,l,r,val,kon);
    if(mid+1<=r) update(2*node+1,mid+1,end,l,r,val,kon);

    /*if(!kon) {
        trow[node] = min(trow[node],trow[2*node]);
        trow[node] = min(trow[node],trow[2*node+1]);
    } else {
        tcol[node] = min(tcol[node],min(tcol[2*node],tcol[2*node+1]));
    }*/
}

ll query(ll node, ll start,ll end,ll l,ll r, ll kon) {
    if(start>end || l>end || r<start) return N-1;

    if(l<=start&&end<=r) {
        if(!kon) {
            return trow[node];
        } else {
            return tcol[node];
        }

    }

    ll mid = (start+end)/2;

    ll left = N-1, right = N-1;

    if(l<=mid) left = query(2*node,start,mid,l,r,kon);
    if(mid+1<=r) right = query(2*node+1,mid+1,end,l,r,kon);

    if(!kon) {
        return min(trow[node],min(left,right));
    } else {
        return min(tcol[node],min(left,right));
    }

}


int main() {
    fastio;

    cin>>N;

    ll Q;
    cin>>Q;
    ll tot = (N-2)*(N-2);

    setup();
    ll t,x;
    while(Q--) {
        cin>>t>>x;
    
        if(t==1) {
            ll mn = query(1,2,N-1,x,x,0);
            tot -= (mn-1);
            // debug(tot,mn,t,x);
            update(1,2,N-1,2,mn,x-1,1);
        } else {
            ll mn = query(1,2,N-1,x,x,1);
            tot -= (mn-1);
            // debug(tot,mn,t,x);
            update(1,2,N-1,2,mn,x-1,0);
        }

    }

    cout<<tot<<endl;
    
}




Measured memory_bytes: 16084