loop do
  n, k = gets.split.map(&:to_i)
  break if n == 0
  points = 3.times.map{ [] }
  k.times do
    c, a, b = gets.split
    a = a.to_i; b = b.to_i
    case c
    when 'yz'
      points[0] << [0, a, b]
    when 'xz'
      points[1] << [a, 0, b]
    when 'xy'
      points[2] << [a, b, 0]
    end
  end
  ans = n * n * n - k * n
  points.each_cons(2) do |ps1, ps2|
    ps1.each do |a|
      ps2.each do |b|
        if a.zip(b).any?{ |p, q| p == q }
          ans += 1
        end
      end
    end
  end
  puts ans
end