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

uint64_t buf[ 500 ][ 500 ][ 8 ];

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

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

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

    memset ( buf, 0, sizeof ( buf ) );
    while ( h-- )
    {
      char c[ 8 ];
      int  a, b;

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

      for ( i = 0; i < n; ++i )
      {
        if ( !strcmp ( c, "xy" ) )
          { buf[ a ][ b ][ i / 64 ] |= 1 << ( i % 64 ); }
        else if ( !strcmp ( c, "xz" ) )
          { buf[ a ][ i ][ b / 64 ] |= 1 << ( b % 64 ); }
        else
          { buf[ i ][ a ][ b / 64 ] |= 1 << ( b % 64 ); }
      }
    }

    for ( i = 0; i < n; ++i )
    for ( j = 0; j < n; ++j )
    for ( k = 0; k < n; ++k )
    {
      t += !!( buf[ i ][ j ][ k / 64 ] & ( 1 << ( k % 64 ) ) );
    }

    printf ( "%d\n", n * n * n - t );
  }

  return ( 0 );
}