def get_parent x
    @parent[x] = get_parent(@parent[x]) if @parent[x] != x
    @parent[x]
end

while true
    h, w = gets.chomp.split.map(&:to_i)
    break if [h, w] == [0, 0]

    map = []
    h.times{map << gets.chomp}
    @parent = (0...(h * w)).to_a
    for y in 0...h
        for x in 0...w
            [[y - 1, x], [y, x - 1]].each{|y2, x2|
                next if y2 < 0 || x2 < 0
                next if map[y2][x2] != map[y][x]
                p1 = get_parent(y * w + x)
                p2 = get_parent(y2 * w + x2)
                min, max = [p1, p2].minmax
                @parent[max] = min
            }
        end
    end
    count = 0
    @parent.each_with_index{|x, i| count += 1 if x == i}
    puts count
end

