h,w = gets.split.map(&:to_i)
a = Array.new(h){ gets.chomp }

seen = Array.new(h){ Array.new(w){ false } }
DX = [ 0, 1, 0,-1, 1,-1, 1,-1]
DY = [ 1, 0,-1, 0, 1,-1,-1, 1]
inside = -> y, x { 0 <= y && y < h && 0 <= x && x < w }

bfs = -> sy,sx do
  que = [[sy,sx]]
  black = 0
  white = 0
  while que.size > 0
    y,x = que.pop
    next if seen[y][x]
    seen[y][x] = true
    a[y][x] == "#" ? black += 1 : white += 1
    4.times do |i|
      ny = y + DY[i]
      nx = x + DX[i]
      next unless inside[ny,nx]
      next if a[y][x] == a[ny][nx] # 同じ色なら対象外
      que << [ny,nx]
    end
  end
  return black * white
end

ans = 0
h.times do |y|
  w.times do |x|
    ans += bfs[y,x]
  end
end
puts ans