// Original C++ solution (slower):
#include <iostream>

#include <vector>

using namespace std;

struct segK{//非再帰

    int n;

    long long MIN;

    int size;

    vector<long long> dat;

    segK(int n_){

        n = 1;

        MIN = 0;

        size = n_;

        while(n < n_) n *= 2;

        dat.resize(2 * n);

        for(int i = 1; i < 2 * n; i++) dat[i] = MIN;

    }

    void update(int k, long long a){

        k += n;

        dat[k] = a;

        while(k > 0){

            k >>= 1;

            dat[k] = max(dat[k << 1 | 0], dat[k << 1 | 1]);

        }

    }

    long long query(int l, int r){

        long long res = 0;

        l += n;

        r += n;

        while(r > l){

            if(l & 1) res = res + dat[l++];

            if(r & 1) res = res + dat[--r];

            l >>= 1;

            r >>= 1;

        }

        return res;

    }

    int right_bin(int l, long long v) {

        if(l == size) return l;

        l += n;

        do {

            while (l % 2 == 0) l >>= 1;

            if (dat[l] >= v) {

                while (l < n) {

                    l = (2 * l);

                    if (dat[l] < v) {

                        l++;

                    }

                }

                return l - n;

            }

            l++;

        } while ((l & -l) != l);

        return size - 1;

    }

    int left_bin(int r, long long v) {

        if(r == 0) return r;

        r += n;

        do {

            r--;

            while (r > 1 && (r % 2)) r >>= 1;

            if (dat[r] <= v) {

                while (r < n) {

                    r = (2 * r + 1);

                    if (dat[r] > v) {

                        r--;

                    }

                }

                return r - n;

            }

        } while ((r & -r) != r);

        return size - 1;

    }

};



int main(){

    long long N, Q;

    cin >> N >> Q;

    segK segtate(N), segyoko(N);

    long long sum = (N - 2) * (N - 2);

    segtate.update(N - 1, N - 1);

    segyoko.update(N - 1, N - 1);

    for(int i = 0; i < Q; i++){

        int t, x;

        cin >> t >> x;

        x--;

        if(t == 1){

            long long ind = segtate.right_bin(0, x);

            sum -= ind - 1;

            segyoko.update(x, ind);

        }

        else {

            long long ind = segyoko.right_bin(0, x);

            sum -= ind - 1;

            segtate.update(x, ind);

        }

    }

    cout << sum << endl;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <map>

using namespace std;

int main(){

    long long N, Q;

    cin >> N >> Q;

    long long sum = (N - 2)*(N - 2);

    vector<long long> tate(N), yoko(N);

    for(int i = 0; i < N; i++){

        tate[i] = N;

        yoko[i] = N;

    }

    int H = N, W = N;

    for(int i = 0; i < Q; i++){

        int t, x;

        cin >> t >> x;

        if(t == 1){

            if(x < W){

                for(int j = x; j < W; j++){

                    yoko[j] = H;

                }

                sum -= yoko[x] - 2;

                W = x;

            }

            else sum -= yoko[x] - 2;

        }

        else{

            if(x < H){

                for(int j = x; j < H; j++){

                    tate[j] = W;

                }

                sum -= tate[x] - 2;

                H = x;

            }

            else sum -= tate[x] - 2;

        }

    }

    cout << sum << endl;

}

// Fastest known solution for this problem: