H, W = gets.split.map(&:to_i)
S = H.times.map{gets.chomp}

visited = Array.new(H){Array.new(W)}
ans = 0
H.times do |i|
    W.times do |j|
        next if visited[i][j]
        visited[i][j]
        num = [0, 0]
        que = [[i, j]]
        while que.size > 0
            x, y = que.shift
            [[-1, 0], [1, 0], [0, -1], [0, 1]].each do |a, b|
                x2 = x+a
                y2 = y+b
                if x2.between?(0, H-1) && y2.between?(0, W-1) && !visited[x2][y2] && S[x][y] != S[x2][y2]
                    que.push([x2, y2])
                    visited[x2][y2] = true
                    num[S[x][y] == '#' ? 1 : 0] += 1
                end
            end
        end
        ans += num[0] * num[1]
    end
end
puts ans