#include<bits/stdc++.h>
using namespace std;
struct SegmentTree{
    int N;
    vector<long long>st;
    vector<bool>cLazy;
    vector<long long>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(long long &cur, long long &l, long long &r) {
        cur = l + r;
    }
    //Handle lazy propagation appriopriately
    void propagate(int node, int L, int R){
        if(L != R){
            cLazy[2 * node] = 1;
            cLazy[2 * node + 1] = 1;
            lazy[2 * node] = lazy[node];
            lazy[2 * node + 1] = lazy[node];
        }
        st[node] = lazy[node];
        cLazy[node] = 0;
    }
    //build the segment tree
    void build(int node, int L, int R){
        if(L == R){
            st[node] = 1e9;
            return;
        }
        int M = (L + R)/2;
        build(2 * node, L, M);
        build(2 * node + 1, M + 1, R);
        merge(st[node], st[2 * node], st[2 * node + 1]);
    }
    //range query
    long long 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;
        long long left = Query(2 * node, L, M, i, j);
        long long right = Query(2 * node + 1, M + 1, R, i, j);
        long long cur;
        merge(cur, left, right);
        return cur;
    }
    //query for a position
    long long 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(2 * node, L, M, pos);
        }
        else
            return pQuery(2 * node + 1, M + 1, R, pos);
    }
    //update a range
    void Update(int node, int L, int R, int i, int j, long long 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]);
    }
    //update a position
    void pUpdate(int node, int L, int R, int pos, long long 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]);
    }
    //position query in main
    long long query(int pos){
        return pQuery(1, 1, N, pos);
    }
    //range query in main
    long long query(int l, int r){
        return Query(1, 1, N, l, r);
    }
    //position update in main
    void update(int pos, long long val){
        pUpdate(1, 1, N, pos, val);
    }
    //range update in main
    void update(int l, int r, long long val){
        Update(1, 1, N, l, r, val);
    }
};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, q;
    cin >> n >> q;
    long long ans = (n - 2) * (n - 2);
    SegmentTree r(n + 1), c(n + 1);
    r.update(1, n, n);
    c.update(1, n, n);
    while(q--){
        long long a, b;
        cin >> a >> b;
        if(a == 1){
            long long s = c.query(b);
            ans -= (s - 2);
            if(r.query(s - 1) > b)
                r.update(1, s - 1, b);
        }
        else{
            long long s = r.query(b);
            ans -= (s - 2);
            if(c.query(s - 1) > b)
                c.update(1, s - 1, b);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 28544