import std.stdio, std.string, std.conv, std.algorithm;

void main(){
    while(true){
        auto input = readln.split.map!(to!int);
        int h = input[0], n = input[1];
        if(n == 0 && h == 0) break;
        int[int] cube;
        foreach(i; 0..n){
            auto line = readln.split;
            int a = line[1].to!int - 1, b = line[2].to!int - 1;
            final switch(line[0]){
                case "xy":
                    foreach(z; 0..h){
                        cube[(a << 18) + (b << 9) + z] = 0;
                    }
                    break;
                case "xz":
                    foreach(y; 0..h){
                        cube[(a << 18) + (y << 9) + b] = 0;
                    }
                    break;
                case "yz":
                    foreach(x; 0..h){
                        cube[(x << 18) + (a << 9) + b] = 0;
                    }
                    break;
            }
        }
        (h * h * h - cube.length).writeln;
    }
}