DBG = true
$h,$w = gets.split.map{|x| x.to_i}
$s = []
for i in 0...$h
  $s <<  gets.chomp
end

def label(col, x, y, lab)
  return [0,0] if $s[x][y] != (col==0 ? '#' : '.') || $marked[x][y]>0
  $marked[x][y] = lab
  difs = [ [-1,0], [1,0], [0,-1], [0,1] ]
  mysums = [0,0]
  for d in difs
    xx = x + d[0]
    yy = y + d[1]
    if 0 <= xx && xx < $h && 0 <= yy && yy < $w
      sums = label(1-col, xx, yy, lab)
      mysums[0] += sums[0]
      mysums[1] += sums[1]
    end
  end
  mysums[col] += 1
  return mysums
end


# # # # main # # # #
$sums = [ [0,0] ]
$marked = Array.new($h)
$marked.map!{Array.new($w)}
for i in 0...$h
  for j in 0...$w
    $marked[i][j] = 0
  end
end

lab = 1
for i in 0...$h
  for j in 0...$w
    if $s[i][j] == '#' && $marked[i][j] == 0
      $sums << label(0, i, j, lab)
      lab += 1
    end
  end
end

psum = 0
for p in $sums
  psum += p[0] * p[1]
end
print psum
