#include<bits/stdc++.h>
#define ll                 long long int
#define mod                1000000007
#define pi                 3.14159265358979323846264338327950288419716939937510
#define setbit(x)          __builtin_popcountll(x)
#define db                 long double
#define pp(x)              pair<x,x>
#define ff                 first
#define ss                 second
#define FIO                ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc                 ll tc; cin>>tc; for(ll number = 1 ; number <= tc ; number ++ )
#define vv(x)              vector<x>
#define pb                 push_back
#define pob                pop_back
#define pf                 push_front
#define pof                pop_front
#define endl               "\n"
#define pq                 priority_queue
#define dbg(x)             { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y)          { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define bp                 ll kkk; cin >>kkk;
#define dbgArr(a,n)        cout<<"Array "<<#a<<endl; for(ll i=0 ; i<n ; i++) cout<<a[i]<<" "; cout<<endl;
#define maxE(a,n)          *max_element(a,a+n);
#define minE(a,n)          *min_element(a,a+n);
#define forn(i,s,n)        for(ll i=s ; i<n ; i++)
#define fornr(i,e,s)       for(ll i=e-1 ; i>=s ; i--)
#define arr1(a,n)          for(ll i=1;i<=n;i++){ cin>>a[i]; }
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define print cout<<"Case #"<<number<<": "
#define all(x) x.begin(), x.end()
ll power(ll x, ll b) {ll p = 1;while (b > 0) {if(b&1) {p = p * x; p %= mod;} b >>= 1; x *= x; x %= mod;} return p % mod;}
using namespace std;
# define INF 1e15
struct ppp{
    ll a,b,c;
};
struct lex_compare {
    bool operator() (ppp p1, ppp p2){
        if(p1.a == p2.a){
            if(p1.b == p2.b) return p1.c < p2.c;
            else return p1.b < p2.b;
        }else{
            return p1.a < p2.a;
        }
    }
};

struct item{
    long long int c;
};

struct segtree{
    long long int sizet;
    vector<item> tree;
    vector<item> lazy;

    void init(long long int n){
        sizet = 1;
        while(sizet < n) sizet *= 2;
        tree.assign(2LL*sizet, single(n-1));
        lazy.assign(2LL*sizet, single(LLONG_MAX-1));
        return ;
    }
    item single(long long int val){
        return {val};
    }

    item NO_OPERATION = single(LLONG_MAX-1);
    item NEUTRAL_ELEMENT = single(0); // For minimum

    item modify_op(item a, item b, long long int len){
        if(b.c == NO_OPERATION.c){
            return a;
        }else{
            return {min(a.c, b.c)};
        }
    }

    item merger(item a, item b){
        return single(min(a.c, b.c));
    }

    void apply_modify_op(item &a, item b, long long int len){
        a = modify_op(a,b,len);
        return ;
    }

    void build(int x, int lx, int rx, vector<long long int> &arr, long long int n){
        if(rx -lx == 1){
            if(lx < n){
                tree[x] = single(arr[lx]);
            }
            return ;
        }
        int m = (lx+rx)/2;
        build(2*x+1, lx, m, arr, n);
        build(2*x+2, m, rx, arr, n);
        tree[x] = merger(tree[2*x+1], tree[2*x+2]);
        return ;
    }
    void build(vector<long long int> &arr){
        long long int n = arr.size();
        build(0, 0, sizet, arr, n);
        return ;
    }
    void propagate(int x, int lx, int rx){
        if(rx -lx == 1){
            return ;
        }
        int m = (lx+rx)/2;
        apply_modify_op(tree[2*x+1], lazy[x], m-lx);
        apply_modify_op(lazy[2*x+1], lazy[x], 1);
        apply_modify_op(tree[2*x+2], lazy[x], rx-m);
        apply_modify_op(lazy[2*x+2], lazy[x], 1);
        lazy[x] = NO_OPERATION;
        return ;
    }

    void modify(int l, int r, long long int val, int x, int lx, int rx){
        if(l >= rx || lx >= r){
            return ;
        }
        propagate(x, lx, rx);
        if( l <= lx && rx <= r){
            apply_modify_op(tree[x],single(val),rx-lx);
            apply_modify_op(lazy[x],single(val),1);
            return ;
        }
        int m = (lx+rx)/2;
        modify(l, r, val, 2*x+1, lx, m);
        modify(l, r, val, 2*x+2, m, rx);
        tree[x] = merger(tree[2*x+1], tree[2*x+2]);
        return ;
    }

    void modify(int l, int r, long long int val){
        modify(l, r, val, 0, 0, sizet);
        return ;
    }

    item get(int i, int x, int lx, int rx){

        propagate(x ,lx, rx);
        if(rx-lx == 1){
            return tree[x];
        }
        int m = (lx+rx)/2;
        if(i < m){
            return get(i, 2*x+1, lx, m);
        }else{
            return get(i, 2*x+2, m, rx);
        }
    }

    ll get(int i){
        return get(i, 0, 0, sizet).c;
    }


};

int main(){
    FIO;
    ll n,m ;
    cin >> n >> m;
    segtree t1, t2; // for row, col
    t1.init(n); t2.init(n);
    ll ans = (n-2)*(n-2);
    //dbg(ans);
    while(m--){
        int x,y; cin >> x >> y;
        y--;
        if(x == 1){
            ll z = t2.get(y);
            ans -= (z-1);
            t1.modify(0, z, y);
        }else{
            ll z = t1.get(y);
            ans -= (z-1);
            t2.modify(0, z, y);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 19568