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

//cubeÌzñðmÛ(³Í1/4)
unsigned char cube[501][501][130];

int main(){
	int i,j,n,a,b,h,m,k,x,y,z;
	char c[3];
	c[2]='\n';
	while(0<=scanf("%d%d",&n,&h)){
		if(n==0 && h==0) break;
		//zñÌú»
		memset(cube,0,sizeof(cube));
		
		//«ÌJ¢ÄécubeÌ
		m=0;
		i=h+1;
		while(--i){
			j=n+1;
			scanf(" %c %c %d%d ",&c[0],&c[1],&a,&b);
			if(c[0]=='x' && c[1]=='y'){
				while(--j){
					//cubeÌ³ª³k³êÄ¢éÌÅA2ÌÝæðgÁÄAÌLè³µð¯Ê
					if((cube[a][b][(j>>2)+1]>>(j%4))%2==1)continue;
					cube[a][b][(j>>2)+1]+=(1<<(j%4));
					++m;
				}
/*				for(x=1;x<=n;++x){
					for(y=1;y<=n;++y){
						for(z=1;z<=n;++z){
							printf("%d ",(cube[x][y][(z>>2)+1]>>(z%4))%2);
						}
						printf("\n");
					}
					printf("\n");
				}*/
				continue;
				
			}
			if(c[0]=='x' && c[1]=='z'){
//			printf("%c%c %d %d\n",c[0],c[1],a,b);
				while(--j){
					if((cube[a][j][(b>>2)+1]>>(b%4))%2==1)continue;
					cube[a][j][(b>>2)+1]+=(1<<(b%4));
					++m;
				}
/*				for(x=1;x<=n;++x){
					for(y=1;y<=n;++y){
						for(z=1;z<=n;++z){
							printf("%d ",(cube[x][y][(z>>2)+1]>>(z%4))%2);
						}
						printf("\n");
					}
					printf("\n");
				}
*/				
				continue;
			}
			if(c[0]=='y' && c[1]=='z'){
//			printf("%c%c %d %d\n",c[0],c[1],a,b);
				while(--j){
//					printf("cube[%d][%d][(%d>>2)+1]=%d\n",j,a,b,cube[j][a][(b>>2)+1]);
					if((cube[j][a][(b>>2)+1]>>(b%4))%2==1)continue;
					cube[j][a][(b>>2)+1]+=(1<<(b%4));
					++m;
			}
/*				for(x=1;x<=n;++x){
					for(y=1;y<=n;++y){
						for(z=1;z<=n;++z){
							printf("%d ",(cube[x][y][(z>>2)+1]>>(z%4))%2);
						}
						printf("\n");
					}
					printf("\n");
				}*/
				continue;
			}
		}
		//ÌJ¢Ä¢È¢cubeÌÂðoÍ
		printf("%d\n",n*n*n-m);
/*		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				for(k=1;k<=n;k++){
					printf("%d ",(cube[i][j][(k>>2)+1]>>(k%4))%2);
				}
				printf("\n");
			}
			printf("\n");
		}
		*/
	}
	return 0;
}