#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
           
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
    int n, h;
    while (scanf("%d%d", &n, &h), n | h)
    {
	vector<int> pos[3 * 2];
	int res = n*n*n;
	while (h--)
	{
	    char c[8];
	    int a[2];
	    scanf("%s%d%d", c, a, a + 1);
	    // xy, xz, yz
	    int p[2], cross[2];
	    if (!strcmp(c, "xy"))
	    {
		p[0] = 0, cross[0] = 2;
		p[1] = 1, cross[1] = 4;
	    }
	    else if (!strcmp(c, "xz"))
	    {
		p[0] = 2, cross[0] = 0;
		p[1] = 3, cross[1] = 5;
	    }
	    else
	    {
		p[0] = 4, cross[0] = 1;
		p[1] = 5, cross[1] = 3;
	    }

	    int passed = 0;
	    bool used[512] = { false };
	    rep (i, 2)
	    {
		pos[p[i]].push_back(a[i]);
		int verti;
		if (cross[i] & 1)
		    verti =cross [i] - 1;
		else
		    verti = cross[i] + 1;

		rep (j, pos[cross[i]].size())
		{
		    if (a[i] == pos[cross[i]][j] && !used[pos[verti][j]])
			++passed, used[pos[verti][j]] = true;
		}
	    }
	    res -= n - passed;
	}
	printf("%d\n", res);
    }
}