/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
    Mbak Seulgi Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int n;
int segx[1200010], segy[1200010];
int lazyx[1200010], lazyy[1200010];
void build(int idx, int l, int r)
{
    lazyx[idx] = lazyy[idx] = 1e9;
    if(l == r) {
        segx[idx] = n;
        segy[idx] = n;
        return;
    }
    int mid = (l+r) / 2;
    build(idx*2, l, mid);
    build(idx*2+1, mid+1, r);
    segx[idx] = min(segx[idx*2], segx[idx*2+1]);
    segy[idx] = min(segy[idx*2], segy[idx*2+1]);
}
void updateX(int idx, int l, int r, int kiri, int kanan, int val)
{
    if(lazyx[idx] != 1e9)
    {
        segx[idx] = min(segx[idx], lazyx[idx]);
        if(l != r)
        {
            lazyx[idx*2] = min(lazyx[idx*2], lazyx[idx]);
            lazyx[idx*2+1] = min(lazyx[idx*2+1], lazyx[idx]);
        }
        lazyx[idx] = 1e9;
    }
    if(l > kanan || r < kiri) return;
    if(l >= kiri && r <= kanan) {
        segx[idx] = min(segx[idx], val);
        if(l != r)
        {
            lazyx[idx*2] = min(lazyx[idx*2], val);
            lazyx[idx*2+1] = min(lazyx[idx*2+1], val);
        }
        return;
    }
    int mid = (l+r) / 2;
    updateX(idx*2, l, mid, kiri, kanan, val);
    updateX(idx*2+1, mid+1, r, kiri, kanan, val);
    segx[idx] = min(segx[idx*2], segx[idx*2+1]);
}
void updateY(int idx, int l, int r, int kiri, int kanan, int val)
{
    if(lazyy[idx] != 1e9)
    {
        segy[idx] = min(segy[idx], lazyy[idx]);
        if(l != r)
        {
            lazyy[idx*2] = min(lazyy[idx*2], lazyy[idx]);
            lazyy[idx*2+1] = min(lazyy[idx*2+1], lazyy[idx]);
        }
        lazyy[idx] = 1e9;
    }
    if(l > kanan || r < kiri) return;
    if(l >= kiri && r <= kanan) {
        segy[idx] = min(segy[idx], val);
        if(l != r)
        {
            lazyy[idx*2] = min(lazyy[idx*2], val);
            lazyy[idx*2+1] = min(lazyy[idx*2+1], val);
        }
        return;
    }
    int mid = (l+r) / 2;
    updateY(idx*2, l, mid, kiri, kanan, val);
    updateY(idx*2+1, mid+1, r, kiri, kanan, val);
    segy[idx] = min(segy[idx*2], segy[idx*2+1]);
}
int queryX(int idx, int l, int r, int kiri, int kanan)
{
    if(lazyx[idx] != 1e9)
    {
        segx[idx] = min(segx[idx], lazyx[idx]);
        if(l != r)
        {
            lazyx[idx*2] = min(lazyx[idx*2], lazyx[idx]);
            lazyx[idx*2+1] = min(lazyx[idx*2+1], lazyx[idx]);
        }
        lazyx[idx] = 1e9;
    }
    if(l > kanan || r < kiri) return 1e9;
    if(l >= kiri && r <= kanan) return segx[idx];
    int mid = (l+r) / 2;
    int le = queryX(idx*2, l, mid, kiri, kanan);
    int ri = queryX(idx*2+1, mid+1, r, kiri, kanan);
    return min(le, ri);
}
int queryY(int idx, int l, int r, int kiri, int kanan)
{
    if(lazyy[idx] != 1e9)
    {
        segy[idx] = min(segy[idx], lazyy[idx]);
        if(l != r)
        {
            lazyy[idx*2] = min(lazyy[idx*2], lazyy[idx]);
            lazyy[idx*2+1] = min(lazyy[idx*2+1], lazyy[idx]);
        }
        lazyy[idx] = 1e9;
    }
    if(l > kanan || r < kiri) return 1e9;
    if(l >= kiri && r <= kanan) return segy[idx];
    int mid = (l+r) / 2;
    int le = queryY(idx*2, l, mid, kiri, kanan);
    int ri = queryY(idx*2+1, mid+1, r, kiri, kanan);
    return min(le, ri);
}
int main()
{
    int i,j,k,x,y,ans,temp,m;
    int tc;
    int q;
    int curr;
    cin >> n >> q;
    build(1, 1, n);
    ll seulgi = 1LL*(n-2)*(n-2);
    while(q--) {
        scanf("%d %d",&x,&y);
        if(y == 1) continue;
        if(x == 1) {
            // row
            curr = queryX(1, 1, n, y, y) - 2;
            seulgi -= curr;
            updateY(1, 1, n, 2, 2 + curr, y);
        } else {
            // col
            curr = queryY(1, 1, n, y, y) - 2;
            seulgi -= curr;
            updateX(1, 1, n, 2, 2 + curr, y);
        }
    }
    cout << seulgi << endl;
    return 0;
}


Measured memory_bytes: 11872