#include "bits/stdc++.h"
using namespace std;

int main() {
	while (1) {
		int N, H; cin >> N >> H;
		if (!N&&!H)break;
		set<tuple<int, int, int>>aset;
		for (int i = 0; i < H; ++i) {
			string  st; int  a, b; cin >> st >> a >> b; a--; b--;
			for (int j = 0; j < N; ++j) {
				if (st=="xy") {
					aset.insert(make_tuple(a, b, j));
				}
				else if (st=="xz") {
					aset.insert(make_tuple(a,j,b));
				}
				else {
					aset.insert(make_tuple(j,a,b));
				}
			}
			
		}
		int ans =N*N*N- aset.size();
		cout <<ans << endl;
	}
	return 0;
}