#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <set>
#include <vector>

using namespace std;

int main() {

  while( true ) {
    int n, h;
    cin >> n >> h;
    if ( n == 0 and h == 0 ) break;
    
    set<tuple<int, int, int>> s;
    for ( int i = 0; i < h; i++ ) {
      string c;
      int a, b;
      cin >> c >> a >> b;
      a--;b--;
      if ( "xy" == c ) {
	for ( int j = 0; j < n; j++ ) {
	  s.insert( make_tuple( a, b, j ) );
	}
      }	else if ( "xz" == c ) {
	for ( int j = 0; j < n; j++ ) {
	  s.insert( make_tuple( a, j, b ) );
	}
      } else {
	for ( int j = 0; j < n; j++ ) {
	  s.insert( make_tuple( j, a, b ) );
	}
      }
    }
    cout << n * n * n - s.size() << endl;
  }
}