#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int ,int> pii;
typedef pair<ll, ll> pll;
typedef double rl;

typedef pii int2;
typedef tuple<int, int, int>           int3;
typedef tuple<int, int, int, int>      int4;
typedef tuple<int, int, int, int, int> int5;

typedef pll ll2;
typedef tuple<ll, ll, ll>         ll3;
typedef tuple<ll, ll, ll, ll>     ll4;
typedef tuple<ll, ll, ll, ll, ll> ll5;

#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define g3(x) get<3>(x)
#define g4(x) get<4>(x)

typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<pll> vll_ll;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vll_ll> vvll_ll;

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define xx first
#define yy second

#define FOR(i,N) for(int i=0; i<N; i++)

#define popc __builtin_popcountll
// #define popc __builtin_popcount

template<typename A>
string to_string(A* ptr)
{
    stringstream ss; ss << "0x" << std::setw(16) << std::setfill ('0') << std::hex << (uint64_t)(uintptr_t)ptr;
    return ss.str();
}

string to_string(char c)
{
    return ((string)"'"+c)+ "'";
}

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#if !ONLINE_JUDGE && 1
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

const int MX=2e5+99;
int N, Q;
int qt[MX], x[MX];

struct segment
{
    ll L, R;
    ll H;
};

string to_string(segment S)
{
    ll3 tmp={S.L, S.R, S.H};
    return to_string(tmp);
}

bool segempty(const segment& S)
{
    dbg(S.L, S.R);
    bool res=S.L>S.R;
    dbg(res);
    return res;
}

bool operator < (const segment& A, const segment& B)
{
    return A.L<B.L;
}

ll solve()
{
    ll result=N-2;
    result*=N-2;

    ll main_x=N-1, main_y=N-1;

    set<segment> HOR, VERT;

    for(int qq=0; qq<Q; qq++)
    {
        int type=qt[qq];
        ll xx=x[qq];

        dbg(HOR);
        dbg(VERT);
        dbg(main_x, main_y);
        dbg("");
        dbg(type, xx);


        if(type==1)
        {
            if(xx<=main_y)
            {
                ll H_main=main_x-2+1;
                result-=H_main;

                segment tmp={xx+1, main_y, H_main};
                main_y=xx-1;
                dbg(tmp);

                if(!segempty(tmp))
                {
                    dbg("insert");
                    HOR.insert(tmp);
                }
            }
            else
            {
                segment tmp={xx, -1, -1};
                auto it=HOR.upper_bound(tmp);
                if(it!=HOR.begin())
                {
                    --it;
                    segment curr=*it;
                    auto [L, R, HH]=curr;
                    if(L<=xx && xx<=R)
                    {
                        result-=HH;
                        segment left={L, xx-1, HH};
                        segment right={xx+1, R, HH};

                        if(!segempty(left)) HOR.insert(left);
                        if(!segempty(right)) HOR.insert(right);
                    }
                }
            }
        }
        else
        {
            assert(type==2);

            if(xx<=main_x)
            {
                ll W_main=main_y-2+1;
                result-=W_main;

                segment tmp={xx+1, main_x, W_main};

                main_x=xx-1;
                if(!segempty(tmp)) VERT.insert(tmp);
            }
            else
            {
                segment tmp={xx, -1, -1};
                auto it=VERT.upper_bound(tmp);
                if(it!=VERT.begin())
                {
                    --it;
                    segment curr=*it;
                    auto [L, R, WW]=curr;
                    if(L<=xx && xx<=R)
                    {
                        result-=WW;
                        segment left={L, xx-1, WW};
                        segment right={xx+1, R, WW};

                        if(!segempty(left)) VERT.insert(left);
                        if(!segempty(right)) VERT.insert(right);
                    }
                }
            }
        }

        dbg("-------------");
    }

    return result;
}

int main()
{
#if !ONLINE_JUDGE && 1
    freopen("F.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
#if 0
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
#endif

    int TT;
#if 0
    cin >> TT;
#else
    TT=1;
#endif
    for(int ttt=0; ttt<TT; ttt++)
    {
        cin >> N >> Q;
        for(int i=0; i<Q; i++)
        {
            cin >> qt[i] >> x[i];
        }

        cout << solve();
    }

    return 0;
}


Measured memory_bytes: 17688