h, w = gets.split.map(&:to_i)
board = Array.new(h) { gets.chomp }

def trav(board, visited, w, h, x, y, white)
  return [0, 0] if x < 0 || x >= w || y < 0 || y >= h

  if white
    return [0, 0] unless board[y][x] == '.'
  else
    return [0, 0] unless board[y][x] == '#'
  end

  return [0, 0] if visited[y][x]
  visited[y][x] = true

  n_black = white ? 0 : 1
  n_white = white ? 1 : 0

  bl, wt = trav(board, visited, w, h, x - 1, y, !white)
  n_black += bl
  n_white += wt
  bl, wt = trav(board, visited, w, h, x + 1, y, !white)
  n_black += bl
  n_white += wt
  bl, wt = trav(board, visited, w, h, x, y - 1, !white)
  n_black += bl
  n_white += wt
  bl, wt = trav(board, visited, w, h, x, y + 1, !white)
  n_black += bl
  n_white += wt

  [n_black, n_white]
end

sum = 0
visited = Hash.new { |hs, k| hs[k] = {} }

h.times do |y|
  w.times do |x|
    next unless board[y][x] == '#'
    next if visited[y][x]
    bl, wt = trav(board, visited, w, h, x, y, false)
    sum += bl * wt
  end
end

puts(sum)