import sys

def solve():

    person = 0

    for i in range(0,H):

        for j in range(0,W):

            if geo[i][j] is not "_":

                search(i,j)

                person += 1

    print(person)

 

def search(i,j):

    temp = geo[i][j]

    geo[i][j] = "_"

    for a in range(0,4):

        idx, jdy = i + dx[a], j + dy[a]

        if(isOnMap(idx, jdy)):

            if(isNeededToSolve(temp, idx, jdy)):

                search(idx,jdy)

 

def isOnMap(i,j): return (0<=i and 0<=j and i<H and j<W)

 

def isNeededToSolve(temp,i,j):

    target = geo[i][j]

    return (target is not "_" and temp is target)

 

limit = 10**7

sys.setrecursionlimit(limit)

 

H, W, tempH = -1, -1, 0

dx = [-1,0,1,0]

dy = [0,-1,0,1]

geo = [[0 for i in range(1)]for j in range(1)]

while True:

    line = eval(input())

    if H is -1 and W is -1:

        p = line.split(" ")

        H, W = int(p[0]), int(p[1])

        geo = [[0 for i in range(W)] for j in range(H)]

    else:

        geo[tempH] = list(line)

        tempH+=1

    if H is 0 and W is 0:break

    if tempH is H:

        solve()

        H, W, tempH = -1, -1, 0
# -*- coding:utf-8 -*-

import sys

def dfs(x, y, sym):

	tile[x][y] = "."

	for i in range(len(DX)):

		nx = x + DX[i]

		ny = y + DY[i]

		if (0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym):

			dfs(nx, ny, sym)



def solve():

	res = 0

	for i in range(N):

		for j in range(M):

			sym = tile[i][j]

			if tile[i][j] != ".":

				if tile[i][j] is sym:

					dfs(i, j, sym)

					res += 1

	print(res)



counter=0

DX = [-1,0,1,0]

DY = [0,-1,0,1]

sys.setrecursionlimit(10**7)

while True:

	line = eval(input())

	if " " in line:

		nums = line.split(" ")

		N = int(nums[0])

		M = int(nums[1])

		tile = [[0 for i in range(M)] for j in range(N)]

	else:

		tile[counter-1] = list(line)

	if N is 0 and M is 0:

		break

	counter += 1

	if counter-1 is N:

		solve()

		counter = 0
import sys


def solve():
    person = 0
    for i in range(0, H):
        for j in range(0, W):
            if geo[i][j] is not "_":
                search(i, j)
                person += 1
    print(person)


def search(i, j):
    temp = geo[i][j]
    geo[i][j] = "_"
    for a in range(0, 4):
        idx, jdy = i + dx[a], j + dy[a]
        if isOnMap(idx, jdy):
            if isNeededToSolve(temp, idx, jdy):
                search(idx, jdy)


def isOnMap(i, j):
    return 0 <= i and 0 <= j and i < H and j < W


def isNeededToSolve(temp, i, j):
    target = geo[i][j]
    return target is not "_" and temp is target


limit = 10**7
sys.setrecursionlimit(limit)
H, W, tempH = -1, -1, 0
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
geo = [[0 for i in range(1)] for j in range(1)]
while True:
    line = eval(input())
    if H is -1 and W is -1:
        p = line.split(" ")
        H, W = int(p[0]), int(p[1])
        geo = [[0 for i in range(W)] for j in range(H)]
    else:
        geo[tempH] = list(line)
        tempH += 1
    if H is 0 and W is 0:
        break
    if tempH is H:
        solve()
        H, W, tempH = -1, -1, 0

# -*- coding:utf-8 -*-
import sys


def dfs(x, y, sym):
    tile[x][y] = "."
    for i in range(len(DX)):
        nx = x + DX[i]
        ny = y + DY[i]
        if 0 <= nx and nx < N and 0 <= ny and ny < M and tile[nx][ny] is sym:
            dfs(nx, ny, sym)


def solve():
    res = 0
    for i in range(N):
        for j in range(M):
            sym = tile[i][j]
            if tile[i][j] != ".":
                if tile[i][j] is sym:
                    dfs(i, j, sym)
                    res += 1
    print(res)


counter = 0
DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]
sys.setrecursionlimit(10**7)
while True:
    line = eval(input())
    if " " in line:
        nums = line.split(" ")
        N = int(nums[0])
        M = int(nums[1])
        tile = [[0 for i in range(M)] for j in range(N)]
    else:
        tile[counter - 1] = list(line)
    if N is 0 and M is 0:
        break
    counter += 1
    if counter - 1 is N:
        solve()
        counter = 0

+# -*- coding:utf-8 -*- -def solve(): -    person = 0 -    for i in range(0, H): -        for j in range(0, W): -            if geo[i][j] is not "_": -                search(i, j) -                person += 1 -    print(person) +def dfs(x, y, sym): +    tile[x][y] = "." +    for i in range(len(DX)): +        nx = x + DX[i] +        ny = y + DY[i] +        if 0 <= nx and nx < N and 0 <= ny and ny < M and tile[nx][ny] is sym: +            dfs(nx, ny, sym) -def search(i, j): -    temp = geo[i][j] -    geo[i][j] = "_" -    for a in range(0, 4): -        idx, jdy = i + dx[a], j + dy[a] -        if isOnMap(idx, jdy): -            if isNeededToSolve(temp, idx, jdy): -                search(idx, jdy) +def solve(): +    res = 0 +    for i in range(N): +        for j in range(M): +            sym = tile[i][j] +            if tile[i][j] != ".": +                if tile[i][j] is sym: +                    dfs(i, j, sym) +                    res += 1 +    print(res) -def isOnMap(i, j): -    return 0 <= i and 0 <= j and i < H and j < W - - -def isNeededToSolve(temp, i, j): -    target = geo[i][j] -    return target is not "_" and temp is target - - -limit = 10**7 -sys.setrecursionlimit(limit) -H, W, tempH = -1, -1, 0 -dx = [-1, 0, 1, 0] -dy = [0, -1, 0, 1] -geo = [[0 for i in range(1)] for j in range(1)] +counter = 0 +DX = [-1, 0, 1, 0] +DY = [0, -1, 0, 1] +sys.setrecursionlimit(10**7) -    if H is -1 and W is -1: -        p = line.split(" ") -        H, W = int(p[0]), int(p[1]) -        geo = [[0 for i in range(W)] for j in range(H)] +    if " " in line: +        nums = line.split(" ") +        N = int(nums[0]) +        M = int(nums[1]) +        tile = [[0 for i in range(M)] for j in range(N)] -        geo[tempH] = list(line) -        tempH += 1 -    if H is 0 and W is 0: +        tile[counter - 1] = list(line) +    if N is 0 and M is 0: -    if tempH is H: +    counter += 1 +    if counter - 1 is N: -        H, W, tempH = -1, -1, 0 +        counter = 0