#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=998244353;


struct SegmentTree
{
    int N;
    vector<ll> st;
    vector<bool> cLazy;
    vector<ll> lazy;

    SegmentTree(int n)
    {
        N = n;
        st.resize(4 * N + 5);
        cLazy.assign(4 * N + 5, false);
        lazy.assign(4 * N + 5, 0);
    }

    //Write reqd merge functions
    void merge(ll &cur, ll &l, ll &r) 
    {
        cur = l + r;
    }
    
    //Handle lazy propagation appriopriately
    void propagate(int node, int L, int R)
    {
        if(L != R)
        {
            cLazy[node*2] = 1;
            cLazy[node*2 + 1] = 1;
            lazy[node*2] = lazy[node];  
            lazy[node*2 + 1] = lazy[node];
        }
        st[node] = lazy[node];
        cLazy[node] = 0;
    }

    void build(int node, int L, int R)
    {
        if(L==R)
        {
            st[node] = 1e9;
            return;
        }
        int M=(L + R)/2;
        build(node*2, L, M);
        build(node*2 + 1, M + 1, R);
        merge(st[node], st[node*2], st[node*2+1]);
    }

    ll Query(int node, int L, int R, int i, int j)
    {
        if(cLazy[node])
            propagate(node, L, R);
        if(j<L || i>R)
            return 0;
        if(i<=L && R<=j)
            return st[node];
        int M = (L + R)/2;
        ll left=Query(node*2, L, M, i, j);
        ll right=Query(node*2 + 1, M + 1, R, i, j);
        ll cur;
        merge(cur, left, right);
        return cur;
    }

    ll pQuery(int node, int L, int R, int pos)
    {
        if(cLazy[node])
            propagate(node, L, R);
        if(L == R)
            return st[node];
        int M = (L + R)/2;
        if(pos <= M)
            return pQuery(node*2, L, M, pos);
        else
            return pQuery(node*2 + 1, M + 1, R, pos);
    }   

    void Update(int node, int L, int R, int i, int j, ll val)
    {
        if(cLazy[node])
            propagate(node, L, R);
        if(j<L || i>R)
            return;
        if(i<=L && R<=j)
        {
            cLazy[node] = 1;
            lazy[node] = val;
            propagate(node, L, R);
            return;
        }
        int M = (L + R)/2;
        Update(node*2, L, M, i, j, val);
        Update(node*2 + 1, M + 1, R, i, j, val);
        merge(st[node], st[node*2], st[node*2 + 1]);
    }

    void pUpdate(int node, int L, int R, int pos, ll val)
    {
        if(cLazy[node])
            propagate(node, L, R);
        if(L == R)
        {
            cLazy[node] = 1;
            lazy[node] = val;
            propagate(node, L, R);
            return;
        }
        int M = (L + R)/2;
        if(pos <= M)
            pUpdate(node*2, L, M, pos, val);
        else
            pUpdate(node*2 + 1, M + 1, R, pos, val);
        merge(st[node], st[node*2], st[node*2 + 1]);
    }

    ll query(int pos)
    {
        return pQuery(1, 1, N, pos);
    }

    ll query(int l, int r)
    {
        return Query(1, 1, N, l, r);
    }

    void update(int pos, ll val)
    {
        pUpdate(1, 1, N, pos, val);
    }

    void update(int l, int r, ll val)
    {
        Update(1, 1, N, l, r, val);
    }
};

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    ll n,q;
    cin>>n>>q;
    ll ans=(n-2)*(n-2);
    SegmentTree r(n+1), c(n+1);
    r.update(1,n-1,n-1);
    c.update(1,n-1,n-1);
    while(q--){
        ll a,b;
        cin>>a>>b; b--;
        if(a==1){
            ll s=c.query(b);
            ans-=(s-1);
            if(r.query(s-1)>b)
                r.update(1,s-1,b);
        }
        else{
            ll s=r.query(b);
            ans-=(s-1);
            if(c.query(s-1)>b)
                c.update(1,s-1,b);
        }
    }
    cout<<ans;



    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

Measured memory_bytes: 28584