#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
  
}

// global variables:
int n, q;
class segment_tree{
private:
  int ST[mn * 4], lazy[mn * 4];
  void UPD(int id, int l, int r, int u, int v, int g) {
    if (lazy[id] < inf) {
      ST[id] = min(lazy[id], ST[id]);
      if (l < r) {
        lazy[id * 2] = min(lazy[id], lazy[id*2]);
        lazy[id * 2 + 1] = min(lazy[id], lazy[id*2 + 1]);
      }
      lazy[id] = inf;
    }

    if (u > r || v < l) return;
    if (u <= l && r <= v) {
      ST[id] = min(ST[id], g);
      if (l < r) {
        lazy[id * 2] = min(lazy[id * 2], g);
        lazy[id * 2 + 1] = min(lazy[id * 2 + 1], g);
      }
      return;
    }

    int mid = (l + r) / 2;
    UPD(id*2, l, mid, u, v, g);
    UPD(id*2 + 1, mid + 1, r, u, v, g);
    ST[id] = min(ST[id*2], ST[id*2 + 1]);
  }

  int GET(int id, int l, int r, int u, int v) {
    if (lazy[id] < inf) {
      ST[id] = min(lazy[id], ST[id]);
      if (l < r) {
        lazy[id * 2] = min(lazy[id], lazy[id*2]);
        lazy[id * 2 + 1] = min(lazy[id], lazy[id*2 + 1]);
      }
      lazy[id] = inf;
    }

    if (u > r || v < l) return inf;
    if (u <= l && r <= v) return ST[id];
    int mid = (l+r)/2;
    return min(GET(id*2, l, mid, u, v), GET(id*2+1, mid+1, r, u, v));
  }
public:
  segment_tree() {
    for (int i=0; i<mn*4; i++) ST[i] = lazy[i] = inf;
  }

  void update(int u, int v, int g) {
    UPD(1, 1, n, u, v, g);
  }

  int get(int u, int v) {
    return GET(1, 1, n, u, v);
  }
} STR, STC;
// main solution goes here:
void execute(int test_number)
{
  cin>>n>>q;
  for (int i=2; i<n; i++) STC.update(i, i, n), STR.update(i, i, n);
  int qq, x;
  int ans = (n-2) * (n-2);
  for (int i=0; i<q; i++) {
    cin>>qq>>x;
    if (qq == 1) {
      int t = STC.get(x, x);
      STR.update(1, t, x);
      ans -= (t - 2);
    } else {
      int t = STR.get(x, x);
      STC.update(1, t, x);
      ans -= (t - 2);
    }
  }

  cout<<ans;
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: https://www.codeforces.com/profile/low_
// ...or linkedIn: https://www.linkedin.com/in/daniel-to-83045a19a/
// I use VS Code. Here's a JSON format for my template: https://pastebin.com/xH2yRdwx


Measured memory_bytes: 28632