#include <stdio.h>
#include <string.h>

int main()
{
	int n, h, i;
	int x, y, z;
	int a, b, sum;
	static char cube[501][501][501];
	char buf[20];

	while (1) {
		scanf("%d %d", &n, &h);
		if (n == 0 && h == 0)
			break;
		memset(cube, 0, 501*501*501);
		//for (x = 0; x <= n; x++) {
		//for (y = 0; y <= n; y++) {
		//for (z = 0; z <= n; z++) {
		//	cube[x][y][z] = 0;
		//}}}
		for (i = 0; i < h; i++) {
			scanf("%s %d %d", buf, &a, &b);
			if (!strcmp(buf, "xy")) {
				for (z = 1; z <= n; z++) {
					cube[a][b][z] = 1;
				}
			} else if (!strcmp(buf, "yz")) {
				for (x = 1; x <= n; x++) {
					cube[x][a][b] = 1;
				}
			} else if (!strcmp(buf, "xz")) {
				for (y = 1; y <= n; y++) {
					cube[a][y][b] = 1;
				}
			}
		}
		sum = 0;
		for (x = 1; x <= n; x++) {
		for (y = 1; y <= n; y++) {
		for (z = 1; z <= n; z++) {
			if (cube[x][y][z] == 0)
				sum++;
		}}}
		printf("%d\n", sum);
	}
	return 0;
}