#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll r[800001];
ll c[800001];
ll rlazy[800001];
ll clazy[800001];
ll n, q;
void init(int node, int x, int y){
    if(x == y){
        r[node] = n;
        c[node] = n;
    }else{
        int mid = (x + y) / 2;
        init(node * 2, x , mid);
        init(node * 2 + 1, mid + 1, y);
        r[node] = r[node * 2];
        c[node] = c[node * 2];
    }
}
void rLazy(int node ,int x,int y){
    if(rlazy[node] != 0){
        r[node] = min(r[node], rlazy[node]);
        if(x != y){
            if(rlazy[node * 2] == 0 || rlazy[node * 2] > rlazy[node]){
                rlazy[node * 2] = rlazy[node];
            }
            if(rlazy[node * 2 + 1] == 0 || rlazy[node * 2 + 1] > rlazy[node]){
                rlazy[node * 2 + 1] = rlazy[node];
            }
        }
        rlazy[node] = 0;
    }
}
void rUpdate(int node, int x,int y,int i,int j, int val){
    rLazy(node, x , y);
    if(x > j || y < i)return;
    if(i <= x && y <= j){
        if(rlazy[node] == 0 || rlazy[node] > val)rlazy[node] = val;
        rLazy(node, x , y);
        return;
    }
    int mid = (x + y) / 2;
    rUpdate(node * 2 , x, mid, i, j, val);
    rUpdate(node * 2 + 1, mid + 1, y, i, j, val);
    r[node] = min(r[node * 2], r[node * 2 + 1]);
}
int rQuary(int node ,int x,int y,int i){
    rLazy(node, x , y);
    if(x > i || y < i)return -1;
    if(i <= x && y <= i)return r[node];
    int mid = (x + y) / 2;
    int Left = rQuary(node * 2, x , mid , i);
    int Right = rQuary(node * 2 + 1, mid + 1, y , i);
    if(Left == -1)return Right;
    else if(Right == -1)return Left;
    else return min(Left, Right);
}

void cLazy(int node ,int x,int y){
    if(clazy[node] != 0){
        c[node] = min(c[node], clazy[node]);
        if(x != y){
            if(clazy[node * 2] == 0 || clazy[node * 2] > clazy[node]){
                clazy[node * 2] = clazy[node];
            }
            if(clazy[node * 2 + 1] == 0 || clazy[node * 2 + 1] > clazy[node]){
                clazy[node * 2 + 1] = clazy[node];
            }
        }
        clazy[node] = 0;
    }
}
void cUpdate(int node, int x,int y,int i,int j, int val){
    cLazy(node, x , y);
    if(x > j || y < i)return;
    if(i <= x && y <= j){
        if(clazy[node] == 0 || clazy[node] > val)clazy[node] = val;
        cLazy(node, x , y);
        return;
    }
    int mid = (x + y) / 2;
    cUpdate(node * 2 , x, mid, i, j, val);
    cUpdate(node * 2 + 1, mid + 1, y, i, j, val);
    c[node] = min(c[node * 2], c[node * 2 + 1]);
}
int cQuary(int node ,int x,int y,int i){
    cLazy(node, x , y);
    if(x > i || y < i)return -1;
    if(i <= x && y <= i)return c[node];
    int mid = (x + y) / 2;
    int Left = cQuary(node * 2, x , mid , i);
    int Right = cQuary(node * 2 + 1, mid + 1, y , i);
    if(Left == -1)return Right;
    else if(Right == -1)return Left;
    else return min(Left, Right);
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> q;
    
    ll ans = (n - (ll)2) * (n - (ll)2);
    init(1, 1, n);

    while(q--){
        int d, x; cin >> d >> x;
        if(d == 1){
            int cnt = cQuary(1, 1, n, x);
            ans -= (ll)(max(0, cnt - 2));

            rUpdate(1, 1, n, 1, cnt, x);
        }else{
            int cnt = rQuary(1, 1, n, x);
            ans -= (ll)(max(0, cnt - 2));
            
            cUpdate(1, 1, n, 1, cnt, x);
        }
    }
    
    cout << ans << '\n';
}


Measured memory_bytes: 19076