#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main()
{
   ll N, Q;
   cin >> N >> Q;
   set<pair<int, int>> tate;
   set<pair<int, int>> yoko;
   tate.insert(make_pair(N, N));
   yoko.insert(make_pair(N, N));
   long long ans = 0;
   for (int i = 0; i < Q; i++)
   {
      int op, x;
      cin >> op >> x;
      if (op == 1)
      {
         auto it = tate.lower_bound(make_pair(x, 0));
         int bound = (*it).second;
         ans += bound - 2;
         yoko.insert(make_pair(bound, x));
      }
      else
      {
         auto it = yoko.lower_bound(make_pair(x, 0));
         int bound = (*it).second;
         ans += bound - 2;
         tate.insert(make_pair(bound, x));
      }
   }
   cout << (N - 2) * (N - 2) - ans << endl;
   return 0;
}
