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
  ans = n * n * n - k * n
  cross = []
  cross_double = []
  points.combination(2).each do |a, b|
    c = a.zip(b)
    if c.any?{ |p, q| p == q }
      cp = c.map{ |p, q| [p, q].max }
      unless cp.any?{ |p| p == 0 }
        unless cross.include?(cp)
          cross << cp
          ans += 1
        else
          unless cross_double.include?(cp)
            cross_double << cp
            ans += 1
          end
        end
      end
    end
  end
  puts ans
end