using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        struct xy {
            public int x;
            public int y;
        }
        public void Solve(ConsoleInput cin) {
            while(true) {
                var N = cin.ReadInt;
                var H = cin.ReadInt;
                if(N == 0 && H == 0) break;
                var zHoles = new List<xy>();
                var xLasers = new bool[N, N];
                var xc = new int[N];
                var yLasers = new bool[N, N];
                var yc = new int[N];
                var range = Enumerable.Range(0, N);
                for(int i = 0; i < H; i++) {
                    var axis = cin.Read;
                    var X = cin.ReadIntArray(2);
                    X[0]--; X[1]--;
                    switch(axis) {
                        case "xy":
                            zHoles.Add(new xy { x = X[0], y = X[1] });
                            break;
                        case "xz":
                            yLasers[X[1], X[0]] = true;
                            yc[X[1]]++;
                            break;
                        case "yz":
                            xLasers[X[1], X[0]] = true;
                            xc[X[1]]++;
                            break;
                    }
                }
                var xyDeleted = range.Sum(z => N * (xc[z] + yc[z]) - xc[z] * yc[z]);
                var newlyDeleted = zHoles.Sum(XY => range.Count(z => !(xLasers[z, XY.y] || yLasers[z, XY.x])));
                Console.WriteLine((long)N * N * N - (xyDeleted + newlyDeleted));
            }
        }
    }

    static class ExtendClass {
        public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }

}



Measured memory_bytes: 19544