#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int C[500][500][500];
int main(void)
{
	int i, j, k;
	while (1) {
		int n, h, x, y, res;
		char p[4];
		scanf("%d%d", &n, &h);
		if (n == 0 && h == 0) break;

		for (i = 0; i < n; ++i)
			for (j = 0; j < n; ++j)
				for (k = 0; k < n; ++k) C[i][j][k] = 0;

		for (i = 0; i < h; ++i) {
			scanf("%s %d%d", p, &x, &y);
			if (strcmp(p, "xy") == 0)
				for (j = 0; j < n; ++j) C[x-1][y-1][j] = 1;
			else if (strcmp(p, "yz") == 0)
				for (j = 0; j < n; ++j) C[j][x-1][y-1] = 1;
			else if (strcmp(p, "xz") == 0)
				for (j = 0; j < n; ++j) C[x-1][j][y-1] = 1;
		}
		res = 0;
		for (i = 0; i < n; ++i)
			for (j = 0; j < n; ++j)
				for (k = 0; k < n; ++k)
					if (!C[i][j][k]) res++;
		printf("%d\n", res);
	}
	return 0;
}