require 'set'

$h, $w = gets.chomp.split.map(&:to_i)
$grid = []
$h.times do
  $grid.push gets.chomp
end

def search(i, j, y, x)
  return if $grid[y][x] == '#'
  return if $set.include?([[i,j], [y,x]])

  $set.add([[i,j], [y,x]])
  $set.add([[y,x], [i,j]])

  search(i, j, y-1, x-1) if y > 0    && x > 0    && ($grid[y-1][x] == '#' || $grid[y][x-1])
  search(i, j, y+1, x-1) if y < $h-1 && x > 0    && ($grid[y+1][x] == '#' || $grid[y][x-1])
  search(i, j, y-1, x+1) if y > 0    && x < $w-1 && ($grid[y-1][x] == '#' || $grid[y][x+1])
  search(i, j, y+1, x+1) if y < $h-1 && x < $w-1 && ($grid[y+1][x] == '#' || $grid[y][x+1])
end


$set = Set.new
$h.times do |i|
  $w.times do |j|
    if $grid[i][j] == '#'
      search(i,j, i-1, j) if i > 0
      search(i,j, i+1, j) if i < $h-1
      search(i,j, i, j-1) if j > 0
      search(i,j, i, j+1) if j < $w-1
    end
  end
end

#p $set
#puts $set.count
puts $set.count / 2
