h, w = gets.split.map(&:to_i)
s = h.times.map {gets.chomp}

v = Array.new(h) {Array.new(w, false)}
ans = 0
h.times do |i|
    w.times do |j|
        next if v[i][j] || s[i][j] == ?.

        que = [[i, j]]
        all = 0
        black = 0
        while now = que.shift
            x, y = now
            next if v[x][y]

            v[x][y] = true
            all += 1
            black += 1 if s[x][y] == ?#

            que << [x-1, y] if x > 0 && s[x][y] != s[x-1][y]
            que << [x+1, y] if x < h-1 && s[x][y] != s[x+1][y]
            que << [x, y-1] if y > 0 && s[x][y] != s[x][y-1]
            que << [x, y+1] if y < w-1 && s[x][y] != s[x][y+1]
        end
        
        ans += (all - black) * black
    end
end

p ans