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

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

def check(x,y,color)
  return [0,0] if x < 0 || W <= x
  return [0,0] if y < 0 || H <= y

  if color == FIELD[y][x]
    m,n = color == '#' ? [1,0] : [0,1]

    FIELD[y][x] = 'x'

    rev_color = color == '#' ? '.' : '#'
    a,b = check(x-1,y,rev_color)
    c,d = check(x+1,y,rev_color)
    e,f = check(x,y-1,rev_color)
    g,h = check(x,y+1,rev_color)
    [m+a+c+e+g,n+b+d+f+h]
  else
    [0,0]
  end

end

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

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