#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int n, h, a, b, c, ans;
bool p[3][501][501]; //xy = 0, xz = 1, yz = 2;

void calc(){
  switch(a){
  case 0:
    for(int i=1;i<=n;++i){
      if(p[1][b][i] || p[2][c][i]) ++ans;
    }
    break;
  case 1:
    for(int i=1;i<=n;++i){
      if(p[0][b][i] || p[2][i][c]) ++ans;
    }
    break;
  case 2:
    for(int i=1;i<=n;++i){
      if(p[0][i][b] || p[1][i][c]) ++ans;
    }
    break;
  }
}

int main(){
  while(cin >> n >> h && (n || h)){
    fill(p[0][0], p[3][0], false);
    ans = n*n*n - h*n;
    for(int i=0;i<h;++i){
      string input;
      cin >> input;
      cin >> b >> c;
      if(input == "xy"){
	a = 0;
      }else if(input == "xz"){
	a = 1;
      }else{
	a = 2;
      }
      if(p[a][b][c]) continue;
      p[a][b][c] = true;
      calc();
    }
    cout << ans << endl;
  }
  return 0;
}