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

$dp = Array.new(h).map { Array.new(w,0)}

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

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

  for a in ary do
    if judge(i+a[0], j+a[1], h, w)
      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
        print $dp
        puts
        dfs(s, i+a[0], j+a[1], hsh, h, w)
      end
    end
  end

  return hsh
end

ans = 0

for i in 0..h-1 do
  for j in 0..w-1 do
    if $dp[i][j] == 0
      if s[i][j] == "#"
        $dp[i][j] = 1
        temp = dfs(s, i, j, {"x" => 1, "y" => 0}, h, w)
      end
      puts temp
      ans += temp["x"] * temp["y"]
    end
  end
end

puts ans
