require 'set'
loop do
  n, k = gets.split.map(&:to_i)
  break if n == 0
  points =
    k.times.map do
      c, a, b = gets.split
      a = a.to_i; b = b.to_i
      case c
      when 'xy'
        [a, b, 0]
      when 'yz'
        [0, a, b]
      when 'xz'
        [a, 0, b]
      end
    end

  cross_points = Set.new
  ans = n * n * n - k * n
  triple = Set.new
  points.combination(2).each do |a, b|
    c = a.zip(b)
    if c.all?{ |p, q| !(p == 0 && q == 0) } && c.any?{ |p, q| p == q }
      cp = c.map{ |p, q| [p, q].max }
      unless cross_points.include?(cp)
        cross_points << cp
        ans += 1
      else
        unless triple.include?(cp)
          triple << cp
          ans += 1
        end
      end
    end
  end
  puts ans
end