H, W = gets.split.map(&:to_i)

GRID = H.times.map { gets.chomp.chars }
VISITED = Array.new(H) { Array.new(W, false) }

ans = 0

H.times do |y|
  W.times do |x|
    next if VISITED[y][x]

    bc = 0
    wc = 0
    que = [[y, x]]

    until que.empty?
      cy, cx = que.shift

      next if VISITED[cy][cx]
      VISITED[cy][cx] = true

      if GRID[cy][cx] == '#'
        bc += 1
      else
        wc += 1
      end

      [[-1, 0], [0, 1], [1, 0], [0, -1]].each do |dy, dx|
        ny = cy + dy
        nx = cx + dx

        next if ny < 0 || nx < 0 || ny >= H || nx >= W
        next if GRID[cy][cx] == GRID[ny][nx]

        que << [ny, nx]
      end
    end

    ans += bc * wc
  end
end

puts ans
