#!/usr/bin/ruby
#
# 1030.rb: Cubes Without Holes
#

require 'set'

### main

szero = Set.new

loop do
  n, h = gets.split.map(&:to_i)
  break if n == 0 && h == 0

  xy = {}
  yx = {}
  yz = {}
  zy = {}
  zx = {}
  xz = {}

  num = n ** 3

  h.times do
    pl, a, b = gets.split

    case pl
    when "xy"
      x = a.to_i
      y = b.to_i

      xy[x] = Set.new if xy[x].nil?
      yx[y] = Set.new if yx[y].nil?
      xy[x] << y
      yx[y] << x

      sxz = xz[x] || szero
      syz = yz[y] || szero
      sxyz = sxz & syz

      num -= n - sxz.size - syz.size + sxyz.size
    when "xz"
      x = a.to_i
      z = b.to_i

      xz[x] = Set.new if xz[x].nil?
      zx[z] = Set.new if zx[z].nil?
      xz[x] << z
      zx[z] << x

      sxy = xy[x] || szero
      szy = zy[z] || szero
      sxzy = sxy & szy

      num -= n - sxy.size - szy.size + sxzy.size
    when "yz"
      y = a.to_i
      z = b.to_i

      yz[y] = Set.new if yz[y].nil?
      zy[z] = Set.new if zy[z].nil?
      yz[y] << z
      zy[z] << y

      syx = yx[y] || szero
      szx = zx[z] || szero
      syzx = syx & szx

      num -= n - syx.size - szx.size + syzx.size
    end
  end

  puts num
end