#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct L {
	int x, y, z;
	int type;
	L() : x(0), y(0), z(0) {}
};

int main() {
	while(true) {
		int n, h;
		cin >> n >> h;
		if(!n && !h) break;

		vector<L> v;
		vector<vector<bool> > cross(h, vector<bool>(h, false));
		int cnt = n*n*n;
		for(int i = 0; i < h; ++i) {
			L l;
			string s;
			cin >> s;
			if(s == "xy") {
				cin >> l.x >> l.y;
				l.type = 0;
			}
			else if(s == "xz") {
				cin >> l.x >> l.z;
				l.type = 1;
			}
			else if(s == "yz") {
				cin >> l.y >> l.z;
				l.type = 2;
			}
			int dupcnt = 0;
			for(int j = 0; j < i; ++j) {
				bool c = false;
				if(l.type == v[j].type) continue;
				if(l.type == 0) {
					if(l.x == v[j].x || l.y == v[j].y) c = true;
				}
				if(l.type == 1) {
					if(l.x == v[j].x || l.z == v[j].z) c = true;
				}
				if(l.type == 2) {
					if(l.y == v[j].y || l.z == v[j].z) c = true;
				}
				if(c) {
					cross[i][j] = cross[j][i] = true;
					for(int k = 0; k < j; ++k) {
						if(cross[i][k] && cross[k][j]) {
							c = false;
							break;
						}
					}
					if(c) ++dupcnt;
				}
			}
			cnt -= n-dupcnt;
			v.push_back(l);
		}
		cout << cnt << endl;
	}
	return 0;
}