H, W = gets.split.map(&:to_i)
*S = *$<, 'x'*W
A = *0...H*W
Spread = lambda{|(i,j)|
	a = A[i*W+j]
	neighbor = "#."[S[i][j].ord&1]
	[[i-1,j],[i,j-1],[i+1,j],[i,j+1]].select{|i,j|
		S[i][j] == neighbor and A[i*W+j] != a
	}.each{|i,j|
		A[i*W+j] = a
	}.each(&Spread)
}
(H*W).times{|a|
	Spread[a.divmod(W)] if A[a] == a
}
B = []
A.each_with_index{|id, iWj|
	(B[id] ||= [0,0])[S[iWj/W][iWj%W].ord&1] += 1
}
p B.compact.inject(0){|a,(o,e)| a + o*e }
