a,b=gets.chomp.split(" ").map { |e| e.to_i }
$h = a
$w = b
s=[]
a.times do |i|
  s[i] = gets.chomp.split("")
end

$dp = Array.new(a).map { Array.new(b,0)}

def judge(i, j)
  if 0 <= i && i < $h && 0<= j && j < $w
    return true
  else
    return false
  end
end

def dfs(s, i, j, hsh)
ary = [[1,0],[-1,0],[0,1],[0,-1]]

for a in ary do
  if judge(i+a[0], j+a[1])
    if $dp[i+a[0]][j+a[1]] == 0 && s[i][j] != s[i+a[0]][j+a[1]]
      $dp[i+a[0]][j+a[1]] = 1
      if s[i+a[0]][j+a[1]] == "#"
        hsh["x"] += 1
      else
        hsh["y"] += 1
      end
      dfs(s, i+a[0], j+a[1], hsh)
    end
  end
end

  return hsh
end

ans = 0

for i in 0..$h-1 do
  for j in 0..$w-1 do

    if s[i][j] == "#" && $dp[i][j] == 0
      $dp[i][j] = 1
      temp = dfs(s, i, j, {"x" => 1, "y" => 0})
      ans += temp["x"] * temp["y"]
    end
  end
end

puts ans
