def dfs(x, y, r)
	$map[x][y] = "."

	[[1, 0], [0, 1], [-1, 0], [0, -1]].each do |move|
		dfs(x + move[0], y + move[1], r) if (x + move[0]).between?(0, $h -1) and (y + move[0]).between?(0, $w - 1) and $map[x + move[0]][ y + move[1]] == r
	end
end

def solve
	result = 0
	%w(@ # *).each do |r|
		(0...$w).each do |x|
			(0...$h).each do |y|
				if $map[x][y] == r
					result += 1
					dfs(x, y, r)
				end
			end
		end
	end
	result
end

$map = []
loop do
	map = []
	$h, $w = gets.split.map(&:to_i)
	break if $h == 0 and $w == 0
	$h.times { $map << gets.chomp.split("")}

	puts solve
end