
require 'pp'

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

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

def depth_search(map, h, w)
  directions = [[1, 0], [-1, 0], [0, 1], [0, -1]]
  stack = []
  visit = []
  stack.push([h, w])
  until stack.empty? do
    h, w = stack.pop
    visit[h] = [] if visit[h].nil?
    visit[h][w] = true
    target = map[h][w]
    map[h][w] = nil
    directions.each do |(i, j)|
      target_next = map[h + i][w + j]
      if target_next != nil and target == target_next then
        stack.push([h + i, w + j])
      end
    end
  end
end

def read_each_data(&proc)
  h, w = $stdin.gets.chomp.split(" ").map(&:to_i)
  return if h == 0 and w == 0
  map = []
  map << Array.new(w + 2, nil)
  h.times do
    map << [nil] + $stdin.gets.chomp.to_a + [nil]
  end
  map << Array.new(w + 2, nil)
  proc.call(map, h, w)
  read_each_data(&proc)
end

read_each_data do |map, height, width|
  counter = 0
  1.upto(height) do |h|
    1.upto(width) do |w|
      if (map[h][w].nil?) then next
      else
        depth_search(map, h, w)
        counter += 1
      end
    end
  end
  puts counter
end