require 'set'; require 'prime'
INF=Float::INFINITY
h,w = gets.chomp.split.map(&:to_i)
grid=[]
h.times do
  grid.push gets.chomp.split(//).map(&:to_sym)
end

kuro = Set.new()
h.times do |i|
  w.times do |j|
    if grid[i][j] == :'#'
      kuro.add [i,j]
    end
  end
end

ans = 0
finished_kuro = Array.new(h){Array.new(w, false)}
dy = [0, 1, 0, -1]; dx = [1, 0, -1, 0]
kuro.each do |y,x|
  q = [[y,x, :'#']]
  next if finished_kuro[y][x] # 通過済み
  visited = Array.new(h){Array.new(w, false)}
  visited[y][x]=true
  bcount = 1
  wcount = 0
  finished_kuro[y][x] = true

  until q.empty?
    y,x,iro = q.pop
    4.times do |i|
      ny = y + dy[i]; nx = x + dx[i]
      if (0 <= ny && ny < h) && (0 <= nx && nx < w) && grid[ny][nx] != iro && !visited[ny][nx]
        if grid[ny][nx] == :'.'
          wcount += 1
        else
          finished_kuro[ny][nx] = true
          bcount += 1
        end
        visited[ny][nx] = true
        q.push [ny, nx, grid[ny][nx]]
      end
    end
  end
  #p [[y,x], bcount, wcount]
  ans += bcount * wcount
end

puts ans
