local ior = io.input()
local h, w = ior:read("*n", "*n", "*l")

local function getindex(i_h, i_w)
  return i_w + (i_h - 1) * w
end

local function createMap()
  local str = ""
  local map = {}
  for i_h = 1, h do
    str = ior:read()
    for i_w = 1, w do
      map[getindex(i_h, i_w)] = (str:sub(i_w, i_w) == "#")
    end
  end
  return map
end

local function uf_initialize(n)
  local parent = {}
  for i = 1, n do parent[i] = i end
  return parent
end

local function uf_findroot(idx, parent)
  while parent[idx] ~= idx do
    idx = parent[idx]
  end
  return idx
end

local map = createMap()
local parent = uf_initialize(h * w)

local function walk(src, dst)
  if map[src] ~= map[dst] then
    local sr, dr = uf_findroot(src, parent), uf_findroot(dst, parent)
    parent[src], parent[dst] = sr, dr
    if sr ~= dr then
      parent[dst], parent[dr] = sr, sr
    end
  end
end

for idx = 1, h * w do
  if w < idx then walk(idx, idx - w) end
  if idx <= (h - 1) * w then walk(idx, idx + w) end
  if 1 < w then
    if idx % w ~= 0 then walk(idx, idx + 1) end
    if idx % w ~= 1 then walk(idx, idx - 1) end
  end
end
local groups = {}
for idx = 1, h * w do
  local r = uf_findroot(idx, parent)
  if not groups[r] then
    local tmp = {0, 0}
    groups[r] = tmp
  end
  if map[idx] then
    groups[r][1] = groups[r][1] + 1
  else
    groups[r][2] = groups[r][2] + 1
  end
end
local ret = 0
for k, v in pairs(groups) do
  ret = ret + v[1] * v[2]
end
print(ret)
