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

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

int main(){
	long int i,j,n,a,b,h,m;
	char c[2];
	while(0<=scanf("%ld%ld",&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 %ld%ld",&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;
				}
				continue;
			}
			if(c[0]=='x' && c[1]=='z'){
				while(--j){
					if((cube[a][j][(b>>2)+1]>>(b%4))%2==1)continue;
					cube[a][j][(b>>2)+1]+=(1<<(b%4));
					++m;
				}
				continue;
			}
			if(c[0]=='y' && c[1]=='z'){
				while(--j){
					if((cube[j][a][(b>>2)+1]>>(b%4))%2==1)continue;
					cube[j][b][(b>>2)+1]+=(1<<(b%4));
					++m;
				}
				continue;
			}
		}
		//ÌJ¢Ä¢È¢cubeÌÂðoÍ
		printf("%ld\n",n*n*n-m);
	}
	return 0;
}