#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

const int tam = 2e5 + 10;

ll row[tam], col[tam];

ll TCol[4*tam], lazyCol[4*tam];
ll TRow[4*tam], lazyRow[4*tam];

#define index int L = 2*nodo+1, R = L+1, mid = (b + e)>>1;

void propagate(int b, int e, int nodo, ll *T, ll *lazy) {
    index;
    if (lazy[nodo] == 0) return;
    if (b != e) {
        T[L] = lazy[L] = lazy[nodo];
        T[R] = lazy[R] = lazy[nodo];
    }
    lazy[nodo] = 0;
}

void update(int b, int e, int nodo, int i, int j, ll val, ll *T, ll *lazy) {
    index;
    if (j < b || e < i) return;
    if (i <= b && e <= j) {
        lazy[nodo] = val;
        T[nodo] = val;
        return;
    }
    propagate(b, e, nodo, T, lazy);
    update(b, mid, L, i, j, val, T, lazy);
    update(mid+1, e, R, i, j, val, T, lazy);
    //T[nodo] = min(T[L], T[R]);
}

ll query(int b, int e, int nodo, int pos, ll *T, ll *lazy) {
    index;
    if (b == e) return T[nodo];
    propagate(b, e, nodo, T, lazy);
    if (pos <= mid) return query(b, mid, L, pos, T, lazy);
    else return query(mid+1, e, R, pos, T, lazy);
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    ll n, q;
    cin >> n >> q;
    ll tot = (n-2)*(n-2);
    ll leftmost = n;
    ll uppermost = n;
    update(0, n, 0, 0, n, n-2, TCol, lazyCol);
    update(0, n, 0, 0, n, n-2, TRow, lazyRow);
    fore(ite, 0, q) {
        int type, x;

        //cout << endl << "Q #" << ite+1 << endl;
        //cout << "Disponibles para las columnas:" << endl;
        fore(i, 2, n) {
            //cout << i << ": " << query(0, n, 0, i, TCol, lazyCol) << endl;
        }
        //cout << "Disponibles para las filas:" << endl;
        fore(i, 2, n) {
            //cout << i << ": " << query(0, n, 0, i, TRow, lazyRow) << endl;;
        }
        cin >> type >> x;
        if (type == 1) {
            ll sub = query(0, n, 0, x, TCol, lazyCol);
            //cout << "quito " << sub << endl;
            tot -= sub;
            if (x < leftmost) {
                leftmost = x;
                update(0, n, 0, 1, 2+sub-1, leftmost-2, TRow, lazyRow);
            }
        }
        else {
            ll sub = query(0, n, 0, x, TRow, lazyRow);
            //cout << "quito " << sub << endl;
            tot -= sub;
            if (x < uppermost) {
                uppermost = x;
                //cout << "uppermost " << uppermost << endl;
                //cout << "cambio de 2 a " << 2+sub-1 << " con " << uppermost-2 << endl;
                update(0, n, 0, 1, 2+sub-1, uppermost-2, TCol, lazyCol);
            }
        }
    }
    cout << tot << '\n';
    return 0;
}
// Dinosaurs are cool!

Measured memory_bytes: 20064