H, W = gets.split.map(&:to_i)
*S = *$<, 'x'*W
A = Array.new(H){ [nil]*W }
H.times{|i|
	W.times{|j|
		s = S[i][j].ord&1
		neighbor = "#."[s]
		(A[i][j] = (
			if S[i-1][j] == neighbor
				A[i-1][j]
			elsif S[i][j-1] == neighbor
				A[i][j-1]
			else
				[0,0]
			end
		))[s] += 1
	}
}
A.flatten!(1).uniq!(&:object_id)
p A.inject(0){|acc,(o,e)| acc + o*e }
