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

typedef struct{
	char xyz[3];
	int a;
	int b;
}stick;

int main(void){

	while(1){
		int n, h, a, b, i, j, k;
		stick sets[200];
		int memo[600][2];

		scanf("%d %d", &n, &h);
		if(n==0 && h==0) {break;}
		
		long count = n*n*n;
		int  memom=0;
		
		for(i=0; i<h; i++) {
			scanf(" %s %d %d", sets[i].xyz, &sets[i].a, &sets[i].b);
		
			long tt = n;
			
			for(j=0; j<i; j++){
				int flag=0;
				for(k=0; k<memom; k++){
					if(memo[k][0]==sets[j].a && memo[k][1]==sets[j].b){
						flag=1;	
					}
				}
				
				if(flag==1) break;
			
				if(strcmp(sets[i].xyz, sets[j].xyz)==0) break;
				else{
					if(sets[j].a == sets[i].a || sets[j].b == sets[i].b)
						tt--;
					if(sets[j].a == sets[i].a && sets[j].b == sets[i].b){
						memo[memom][0]=sets[i].a;
						memo[memom][1]=sets[i].b;
						memom++;
					}
				}	
				
			}	
			//printf("tt= %ld\n",tt);
			count -= tt;	
		}
				
		printf("%ld\n", count);
						
	}

	return 0;
}