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 = Set.new()
dy = [0, 1, 0, -1]; dx = [1, 0, -1, 0]
kuro.each do |y,x|
  q = [[y,x, :'#']]
  next if finished_kuro.include?([y,x]) # 通過済み
  black = Set.new([[y,x]])
  white = Set.new()

  until q.empty?
    y,x,iro = q.shift
    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 && !white.include?([ny,nx]) && !black.include?([ny,nx])
        if grid[ny][nx] == :'.'
          white.add [ny,nx]
        else
          black.add [ny,nx]
        end
        q.push [ny, nx, grid[ny][nx]]
      end
    end
  end

  ans += black.size * white.size
  finished_kuro.merge black
end

puts ans
