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

template<typename F, typename T, typename Func_mf, typename Func_op, typename Func_mv>
struct LazySegtree {
    int n, n_org;
    vector<T> dat;
    vector<F> laz;
    Func_mf merge_functions;
    Func_op operate;
    Func_mv merge_values;
    F fe;
    T te;

    LazySegtree(){}
    LazySegtree(int n_org,
                Func_mf merge_functions,
                Func_op operate,
                Func_mv merge_values,
                F fe, T te):
                n_org(n_org),
                merge_functions(merge_functions),
                operate(operate),
                merge_values(merge_values),
                fe(fe), te(te){
        n = 1;
        while(n < n_org) n <<= 1;
        dat.assign(2*n-1, te);
        laz.assign(2*n-1, fe);
    }

    void build(vector<T>& A){
        for(int k=0; k<int(A.size()); k++) dat[k+n-1] = A[k];
        for(int k=n-2; k>=0; k--) dat[k] = merge_values(dat[2*k+1], dat[2*k+2]);
    }

    void eval(int k, int w){
        if(laz[k] == fe) return;
        operate(dat[k], laz[k], w);
        if(k < n-1){
            merge_functions(laz[2*k+1], laz[k]);
            merge_functions(laz[2*k+2], laz[k]);
        }
        laz[k] = fe;
    }

    void update_between(int a, int b, F x){
        update(a, b+1, x, 0, 0, n);
    }

    void update(int a, int b, F x, int k, int lb, int rb){
        eval(k, rb-lb);
        if(b <= lb || rb <= a) return;
        if(a <= lb && rb <= b){
            merge_functions(laz[k], x);
            eval(k, rb-lb);
        }else{
            int mb = (lb+rb)>>1;
            update(a, b, x, 2*k+1, lb, mb);
            update(a, b, x, 2*k+2, mb, rb);
            dat[k] = merge_values(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get_between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int lb, int rb){
        eval(k, rb-lb);
        if(rb<=a || b<=lb) return te;
        if(a<=lb && rb<=b) return dat[k];
        int mb = (lb+rb)>>1;
        T vl = query(a, b, 2*k+1, lb, mb);
        T vr = query(a, b, 2*k+2, mb, rb);
        return merge_values(vl, vr);
    }

    // [S, t] が条件checkを満たす最大のtを求める
	template<typename Func_ck>
    int lower_bound(int S, Func_ck check){
        T val = get_between(S, S);
        int k = S+n-1;
        int lb = S, rb = S+1;
        while(true){
            while(k%2){
                k = (k-1)/2;
                rb += rb-lb;
            }
			int w = rb-lb;
            eval(k, w);
            T val2 = merge_values(val, dat[k]);
            if(check(val2)){
                if(rb == n) return n_org-1;
                val = val2;
                k++;
				lb += w;
				rb += w;
            }else{
                break;
            }
        }
        while(k<n-1){
            int wh = (rb-lb)>>1;
            eval(2*k+1, wh);
            eval(2*k+2, wh);
            T val2 = merge_values(val, dat[2*k+1]);
            if(check(val2)){
                val = val2;
                k = 2*k+2;
                lb += wh;
            }else{
                k = 2*k+1;
                rb -= wh;
            }
        }
        return min(lb, n_org)-1;
    }
};

void chmin(int& a, int b){
    a = min(a, b);
}

auto make_segtree = [](int N){
    using F = int;
    using T = int;
    auto merge_functions = [](F& f, F& g){
        chmin(f, g);
    };
    auto operate = [](T& v, F& f, int w){
        chmin(v, f);
    };
    auto merge_values = [](T& a, T& b){
        return min(a, b);
    };
    F fe = 1e9;
    T te = 1e9;
    return LazySegtree<F, T, decltype(merge_functions), decltype(operate), decltype(merge_values)>
        (N, merge_functions, operate, merge_values, fe, te);
};

int main(){
    int N, Q;
    cin >> N >> Q;
    int64_t ans = int64_t(N-2)*(N-2);
    auto st1 = make_segtree(N+1);
    auto st2 = make_segtree(N+1);
    vector<int> init(N+1, N);
    st1.build(init);
    st2.build(init);
    while(Q--){
        int t, x;
        cin >> t >> x;
        if(t == 1){
            int pos = st1.get_between(x, x);
            ans -= pos-2;
            st2.update_between(2, pos-1, x);
        }else{
            int pos = st2.get_between(x, x);
            ans -= pos-2;
            st1.update_between(2, pos-1, x);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12188