def nxt(i,j,h,w)
  ret = []
  ret << [i-1,j] if i > 0
  ret << [i+1,j] if i < h-1
  ret << [i,j-1] if j > 0
  ret << [i,j+1] if j < w-1
  return ret
end

h,w = gets.split.map(&:to_i)
s = []
h.times do 
  s << gets.chomp
end
table=Array.new(h){Array.new(w,true)}
id = 1
ans = 0
h.times do |i|
  w.times do |j|
    if table[i][j]
      table[i][j] = false
      search = [[i,j]]
      cnt = [0,0]
      cnt[s[i][j]=="#" ? 0 : 1] += 1
      while tmp = search.shift
        a,b = tmp
        color = s[a][b] == "#" ? "." : "#"
        nxt(a,b,h,w).each do |x,y|
          if table[x][y] && s[x][y] == color
            table[x][y] = false
            search << [x,y]
            cnt[s[x][y]=="#" ? 0 : 1] += 1
          end
        end
      end
      ans += cnt[0]*cnt[1]
      #p cnt
    end
  end
end
p ans