h, w = gets.split.map(&:to_i)
board = Array.new(h) { gets.chomp }

sum = 0
visited = Hash.new { |hs, k| hs[k] = {} }

h.times do |y|
  w.times do |x|
    next unless board[y][x] == '#'
    next if visited[y][x]

    n_black = 0
    n_white = 0
    stack = [[x, y, false]]
    while !stack.empty?
      xx, yy, white = stack.pop

      next if xx < 0 || xx >= w || yy < 0 || yy >= h

      if white
        next unless board[yy][xx] == '.'
      else
        next unless board[yy][xx] == '#'
      end

      next if visited[yy][xx]
      visited[yy][xx] = true

      if white
        n_black += 1
      else
        n_white += 1
      end

      stack << [xx - 1, yy, !white]
      stack << [xx + 1, yy, !white]
      stack << [xx, yy- 1, !white]
      stack << [xx, yy + 1, !white]
    end
    sum += n_black * n_white
  end
end

puts(sum)