#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

class Dots{
public:
	int x;
	int y;
	int z;

	Dots(){
		x=y=z=-1;
	}
	Dots(int x_,int y_,int z_){
		x=x_;
		y=y_;
		z=z_;
	}

	bool operator==(const Dots &d)const{
		return (d.x==this->x&&d.y==this->y&&d.z==this->z);
	}
};

int h,n;

int main(){

	while(cin>>n>>h&&!(n==0&&h==0)){
		int sum=n*n*n;
		vector<Dots> ds;
		vector<Dots> exited;
		for(int i = 0; i < h; i++){
			string str;
			cin>>str;
			Dots d;
			if(str=="xy"){
				d.z=0;
				cin>>d.x>>d.y;
			}
			else if(str=="xz"){
				d.y=0;
				cin>>d.x>>d.z;
			}
			else{
				d.x=0;
				cin>>d.y>>d.z;
			}
			ds.push_back(d);
		}
		int cnt=0;
		vector<Dots> v2;
		for(int i = 0; i < ds.size(); i++){
			cnt+=n;
			exited.clear();
			for(int j = 0; j < ds.size(); j++){
				if(i==j)
					continue;
				if(ds[i].x==0){
					if(ds[j].x==0){
						continue;
					}
					else if(ds[j].y==0){
						if(ds[i].z==ds[j].z){
							//cross
							Dots td(ds[j].x,ds[i].y,ds[i].z);
							if(find(exited.begin(),exited.end(),td)==exited.end()){
								exited.push_back(td);
								cnt--;
							}
							if(find(v2.begin(),v2.end(),td)==v2.end()){
								v2.push_back(td);
							}
						}
					}
					else if(ds[j].z==0){
						if(ds[i].y==ds[j].y){
							//cross
							Dots td(ds[j].x,ds[i].y,ds[i].z);
							if(find(exited.begin(),exited.end(),td)==exited.end()){
								exited.push_back(td);
								cnt--;
							}
							if(find(v2.begin(),v2.end(),td)==v2.end()){
								v2.push_back(td);
							}
						}
					}
				}
				else if(ds[i].y==0){
					if(ds[j].y==0){
						continue;
					}
					else if(ds[j].x==0){
						if(ds[i].z==ds[j].z){
							//cross
							Dots td(ds[i].x,ds[j].y,ds[i].z);
							if(find(exited.begin(),exited.end(),td)==exited.end()){
								exited.push_back(td);
								cnt--;
							}
							if(find(v2.begin(),v2.end(),td)==v2.end()){
								v2.push_back(td);
							}
						}
					}
					else if(ds[j].z==0){
						if(ds[i].x==ds[j].x){
							//cross
							Dots td(ds[i].x,ds[j].y,ds[i].z);
							if(find(exited.begin(),exited.end(),td)==exited.end()){
								exited.push_back(td);
								cnt--;
							}
							if(find(v2.begin(),v2.end(),td)==v2.end()){
								v2.push_back(td);
							}
						}
					}
				}
				else if(ds[i].z==0){
					if(ds[j].z==0){
						continue;
					}
					else if(ds[j].x==0){
						if(ds[i].y==ds[j].y){
							//cross
							Dots td(ds[i].x,ds[j].y,ds[j].z);
							if(find(exited.begin(),exited.end(),td)==exited.end()){
								exited.push_back(td);
								cnt--;
							}
							if(find(v2.begin(),v2.end(),td)==v2.end()){
								v2.push_back(td);
							}
						}
					}
					else if(ds[j].y==0){
						if(ds[i].x==ds[j].x){
							//cross
							Dots td(ds[j].x,ds[i].y,ds[j].z);
							if(find(exited.begin(),exited.end(),td)==exited.end()){
								exited.push_back(td);
								cnt--;
							}
							if(find(v2.begin(),v2.end(),td)==v2.end()){
								v2.push_back(td);
							}
						}
					}
				}
			}
		}
		cout<<sum-cnt-v2.size()<<endl;
	}

	return 0;
}

Measured memory_bytes: 0