#include <iostream>
#include <string>
#include <set>
using namespace std;

class Point {
public:
  int x, y, z;
  Point(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
  bool operator <(const Point &p) const{
    if(z != p.z) return z < p.z;
    if(y != p.y) return y < p.y;
    if(x != p.x) return x < p.x;
    return false;
  }
};

int main() {
  while(1) {
    int n, h;
    cin >> n >> h;
    if(n == 0 && h == 0) break;

    set<Point> hole;
    for(int i = 0; i < h; i++) {
      string str;
      int a, b;
      cin >> str >> a >> b;
      if(str == "xy") {
	for(int j = 1; j <= n; j++) {
	  hole.insert(Point(a, b, j));
	}
      } else if(str == "xz") {
	for(int j = 1; j <= n; j++) {
	  hole.insert(Point(a, j, b));
	}
      } else if(str == "yz") {
	for(int j = 1; j <= n; j++) {
	  hole.insert(Point(j, a, b));
	}
      }
    }

    cout << n*n*n - hole.size() << endl;
  } 

  return 0;
}