require 'set'

loop {
	n, h = gets.split.map &:to_i
	break if n == 0

	used_x = {}
	used_y = {}
	z_lines = Set.new

	h.times {
		face, u, v = gets.split
		u = u.to_i
		v = v.to_i
		case face
		when 'xy'
			z_lines << [u, v]
		when 'xz'
			(used_x[v] ||= Set.new) << u
		when 'yz'
			(used_y[v] ||= Set.new) << u
		end
	}

	count = 0
	(1..n).each{|z|
		a = used_x[z] || []
		b = used_y[z] || []
		count += n * (a.size + b.size) - a.size * b.size
		z_lines.each{|x, y|
			count += 1 unless a.include?(x) && b.include?(y)
		}
	}
	p n**3 - count
}