h, w = gets.split.map(&:to_i)
list = h.times.map{ gets.chomp.split('') }
s = list.flatten.map.with_index{ |c, i| i if c == '#' }.compact
move = [[-1, 0], [0, 1], [1, 0], [0, -1]]
ans = 0

s.each do |i|
  x = i % w
  y = i / w
  q = [[x, y, 0]]
  visited = h.times.map{ [false] * w }
  visited[y][x] = true
  until q.empty?
    x, y, color = q.shift
    move.each do |mx, my|
      nx = x + mx
      ny = y + my
     if 0 <= nx && nx < w && 0 <= ny && ny < h
        if !visited[ny][nx]
          visited[ny][nx] = true
          if color == 0 && list[ny][nx] == '.' || color == 1 && list[ny][nx] == '#'
            q << [nx, ny, 1 - color]
            if color == 0
              ans += 1
            end
          end
        end
      end
    end
  end
end
puts ans
      

