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


void faster()
{
	int n, h, i, j, k;
	int x, y, z;
	int a, b, sum;
	int X[200], Y[200], Z[200];
	char buf[20];
	int count;
	int p;

	while (1) {
		scanf("%d %d", &n, &h);
		if (n == 0 && h == 0)
			break;
		p = 0;
		for (i = 0; i < h; i++) {
			scanf("%s %d %d", buf, &a, &b);
			if (!strcmp(buf, "xy")) {
				X[p] = a;
				Y[p] = b;
				Z[p] = 0;
			} else if (!strcmp(buf, "yz")) {
				X[p] = 0;
				Y[p] = a;
				Z[p] = b;
			} else if (!strcmp(buf, "xz")) {
				X[p] = a;
				Y[p] = 0;
				Z[p] = b;
			}
			// 重複チェック
			for (j = 0; j < p; j++) {
				if ( X[p] == X[j] && Y[p] == Y[j] && Z[p] == Z[j] ) {
					break;
				}
			}
			if (j == p)
				p++;
		}
		count = 0;
		for (i = 1; i < p; i++) {
			for (j = 0; j < i; j++) {
				if ( (X[i] == X[j] || X[i] * X[j] == 0) &&
					 (Y[i] == Y[j] || Y[i] * Y[j] == 0) && 
					 (Z[i] == Z[j] || Z[i] * Z[j] == 0) ) {
					count++;
					break;
				}
			}
		}
		printf("%d\n", n * n * n - n * p + count);
	}
}

void consevativ()
{
	int n, h, i, j, k;
	int x, y, z;
	int a, b, sum;
	static char cube[501][501][501] = {0};
	char buf[20];
	int count;
	int p;

	while (1) {
		scanf("%d %d", &n, &h);
		if (n == 0 && h == 0)
			break;
		p = 0;
		for (x = 1; x <= n; x++) {
		for (y = 1; y <= n; y++) {
		for (z = 1; 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;
				}
			}
		}
		count = 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)
				count++;
		}}}
		printf("%d\n", count);
	}
}

int main()
{
//	faster();
	consevativ();
	return 0;
}