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

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

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

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

  (white ? 1 : 0) +
      trav(board, visited, w, h, x - 1, y, !white) +
      trav(board, visited, w, h, x + 1, y, !white) +
      trav(board, visited, w, h, x, y - 1, !white) +
      trav(board, visited, w, h, x, y + 1, !white)

end

sum = 0
h.times do |y|
  w.times do |x|
    next unless board[y][x] == '#'

    visited = Hash.new { |hs, k| hs[k] = {} }
    sum += trav(board, visited, w, h, x, y, false)
  end
end
puts(sum)