// AOJ 1030 Cubes Without Holes
// 2018.2.3 bal4u@uu

#include <stdio.h>

#include <stdio.h>
#include <string.h>
 
char buf[15], *p;
int in()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

char f[134217728];
int ans;
 
int main()
{
	int cno, n, h, a, b, i, k, t, ans;
	char *c;

	cno = 0;
	while (fgets(p=buf, 15, stdin) && *p != '0') {
		cno++;
		n = in(), h = in();

		ans = 0;
		while (h--) {
			fgets(p=buf, 15, stdin);
			c = p, p += 3, a = in()-1, b = in()-1;
			if (*c == 'x' && *(c+1) == 'y') {
				t = (a << 18) | (b << 9);
				i = n; while (i--) {
					k = i | t;
					if (f[k] != cno) f[k] = cno, ans++;
				}
			} else if (*c == 'x' && *(c+1) == 'z') {
				t = (a << 18) | b;
				i = n; while (i--) {
					k = t | (i << 9);
					if (f[k] != cno) f[k] = cno, ans++;
				}
			} else {
				t = (a << 9) | b;
				i = n; while (i--) {
					k = t | (i << 18);
					if (f[k] != cno) f[k] = cno, ans++;
				}
			}
		}
		printf("%d\n", n*n*n - ans);
	}
	return 0;
}
