#include <stdio.h>
#include <string.h>

#define N 500

int sigma[ N ][ N ][ N ];

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j, k;

  for ( ; ; )
  {
    int res = 0;
    int n, h;

    scanf ( " %d %d", &n, &h );
    if ( !( n | h ) ) break ;

    memset ( sigma, 0, sizeof ( sigma ) );

    for ( i = 0; i < h; ++i )
    {
      char c[ 2 ];
      int a, b;

      scanf ( " %c%c %d %d", c, c + 1, &a, &b );
      --a; --b;

      for ( j = 0; j < n; ++j )
      {
        if ( c[ 0 ] == 'x' && c[ 1 ] == 'y' )
        {
          sigma[ a ][ b ][ j ] = 1;
        }
        if ( c[ 0 ] == 'x' && c[ 1 ] == 'z' )
        {
          sigma[ a ][ j ][ b ] = 1;
        }
        if ( c[ 0 ] == 'y' && c[ 1 ] == 'z' )
        {
          sigma[ j ][ a ][ b ] = 1;
        }
      }
    }

    for ( i = 0; i < n; ++i )
    for ( j = 0; j < n; ++j )
    for ( k = 0; k < n; ++k )
    {
      res += !( sigma[ i ][ j ][ k ] );
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}