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

FIELD=[]
H.times do
  FIELD << gets.chomp
end

def check(x,y,color)
  ret = [0,0]
  queue = [[x,y,color]]

  until queue.empty?
    x,y,color = queue.pop
    next if x < 0 || W <= x
    next if y < 0 || H <= y
    if color == FIELD[y][x]
      FIELD[y][x] = 'x'
      if color == '#'
        ret[0] += 1
        rev_color = '.'
      else
        ret[1] += 1
        rev_color = '#'
      end
      queue << [x-1,y,rev_color]
      queue << [x+1,y,rev_color]
      queue << [x,y-1,rev_color]
      queue << [x,y+1,rev_color]
    end
  end
  
  ret
end

ret = []
H.times do |y|
  W.times do |x|
    ret << check(x,y,'.')
  end
end

ret_n = 0
ret.each do |a,b|
  ret_n += a*b
end
p ret_n