#include <iostream>
#include <vector>
#include <set>
#include <utility>
using namespace std;

int main()
{
    int N;
    cin>>N;
    int Q;
    cin>>Q;

    set<pair<int, int>> R, C;
    R.insert({N-1, N-1});
    C.insert({N-1, N-1});

    long long ans = (long long)(N-2)*(N-2);
    for (int q=0; q<Q; q++)
    {
        int rc;
        cin>>rc;
        set<pair<int, int>> &S1 = rc==1 ? R : C;
        set<pair<int, int>> &S2 = rc==1 ? C : R;
        int x;
        cin>>x;
        x--;

        pair<int, int> s = *S2.lower_bound(make_pair(x, -1));
        ans -= s.second-1;
        S1.insert({s.second, x});
    }
    cout<<ans<<endl;
}
