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] << [a, b]
    when 'xz'
      points[1] << [a, b]
    when 'xy'
      points[2] << [a, b]
    end
  end
  ans = n * n * n - k * n
  points[0].each do |p|
    points[1].each do |q|
      if p[1] == q[1]
        ans += 1
      end
    end
  end
  points[0].each do |p|
    points[2].each do |q|
      if p[0] == q[1]
        ans += 1
      end
    end
  end
  puts ans
end