
class String
  def to_a
    self.bytes.to_a.map(&:chr)
  end
end

# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0118

H, W = $stdin.gets.split(" ").map(&:to_i)
map = []
map << Array.new(H + 2, nil)
W.times do
  map << [nil] + $stdin.gets.chomp.to_a + [nil]
end
map << Array.new(H + 2, nil)

def depth_search(map, h, w)
  directions = [[1, 0], [-1, 0], [0, 1], [0, -1]]
  target = map[h][w]
  map[h][w] = nil
  directions.map do |(i, j)|
    target_next = map[h + i][w + j]
    if target_next != nil and target == target_next then
      depth_search(map, h + i, w + j)
    end
  end
end

counter = 0

1.upto(H) do |h|
  1.upto(W) do |w|
    if (map[h][w].nil?) then next
    else
      depth_search(map, h, w)
      counter += 1
    end
  end
end

puts counter

# pp map
# pp H, W