h,w = gets.split.map(&:to_i)
used = Array.new(h).map{Array.new(w,false)}
s = h.times.map{gets.chomp}
ans = 0
h.times do |i|
    w.times do |j|
        next if used[i][j]
        q = [[i,j]]
        used[i][j] = true
        a = b = 0
        if s[i][j] == "."
            a += 1
        else
            b += 1
        end
        while q.any?
            x,y = q.shift
            if x != 0 && s[x][y] != s[x-1][y] && !used[x-1][y]
                q.push([x-1,y])
                used[x-1][y] = true
                if s[x-1][y] == "."
                    a += 1
                else
                    b += 1
                end
            end
            if x != h-1 && s[x][y] != s[x+1][y] && !used[x+1][y]
                q.push([x+1,y])
                used[x+1][y] = true
                if s[x+1][y] == "."
                    a += 1
                else
                    b += 1
                end
            end
            if y != 0 && s[x][y] != s[x][y-1] && !used[x][y-1]
                q.push([x,y-1])
                used[x][y-1] = true
                if s[x][y-1] == "."
                    a += 1
                else
                    b += 1
                end
            end
            if y != w-1 && s[x][y] != s[x][y+1] && !used[x][y+1]
                q.push([x,y+1])
                used[x][y+1] = true
                if s[x][y+1] == "."
                    a += 1
                else
                    b += 1
                end
            end
        end
        ans += a*b
    end
end
puts ans