def Labeling(terrain):



    label = terrain



    offset = [[-1, 0], [0, -1], [1, 0], [0, 1]]

    signs = ["@", "#", "*"]

    step = 0



    for row in range(1, len(label) - 1):

        for col in range(1, len(label[row]) - 1):

            mark = label[row][col]



            if mark in signs:

                pointStack = [[row, col]]

                label[row][col] = step



                while 0 < len(pointStack):

                    rowIndex, colIndex = pointStack.pop()



                    for x, y in offset:

                        offsetRow, offsetCol = rowIndex + x, colIndex + y



                        if label[offsetRow][offsetCol] == mark:

                            pointStack.append([offsetRow, offsetCol])

                            label[offsetRow][offsetCol] = step



                step += 1



    return step





Sentinel = "1"



while True:

    col, row = [int(item) for item in input().split()]



    if row == 0 and col == 0:

        break



    land = []

    land.append([item for item in Sentinel * row + Sentinel * 2])



    for lp in range(col):

        part = [item for item in eval(input())]

        land.append([])

        land[-1].extend([Sentinel])

        land[-1].extend(part)

        land[-1].extend([Sentinel])



    land.append([item for item in Sentinel * row + Sentinel * 2])



    result = Labeling(land)



    print(result)



def Labeling(terrain):



    label = terrain



    offset = [[-1, 0], [0, -1], [1, 0], [0, 1]]

    signs = ["@", "#", "*"]

    rowLength, colLength = len(label) - 1, len(label[0]) - 1



    step = 0



    for row in range(1, rowLength):

        for col in range(1, colLength):

            mark = label[row][col]



            if mark in signs:

                pointStack = [[row, col]]

                label[row][col] = step



                while 0 < len(pointStack):

                    rowIndex, colIndex = pointStack.pop()



                    for x, y in offset:

                        offsetRow, offsetCol = rowIndex + x, colIndex + y



                        if label[offsetRow][offsetCol] == mark:

                            pointStack.append([offsetRow, offsetCol])

                            label[offsetRow][offsetCol] = step



                step += 1



    return step





Sentinel = "1"



while True:

    col, row = [int(item) for item in input().split()]



    if row == 0 and col == 0:

        break



    land = []

    land.append([item for item in Sentinel * row + Sentinel * 2])



    for lp in range(col):

        part = [item for item in eval(input())]

        land.append([])

        land[-1].extend([Sentinel])

        land[-1].extend(part)

        land[-1].extend([Sentinel])



    land.append([item for item in Sentinel * row + Sentinel * 2])



    result = Labeling(land)



    print(result)



def Labeling(terrain):
    label = terrain
    offset = [[-1, 0], [0, -1], [1, 0], [0, 1]]
    signs = ["@", "#", "*"]
    step = 0
    for row in range(1, len(label) - 1):
        for col in range(1, len(label[row]) - 1):
            mark = label[row][col]
            if mark in signs:
                pointStack = [[row, col]]
                label[row][col] = step
                while 0 < len(pointStack):
                    rowIndex, colIndex = pointStack.pop()
                    for x, y in offset:
                        offsetRow, offsetCol = rowIndex + x, colIndex + y
                        if label[offsetRow][offsetCol] == mark:
                            pointStack.append([offsetRow, offsetCol])
                            label[offsetRow][offsetCol] = step
                step += 1
    return step


Sentinel = "1"
while True:
    col, row = [int(item) for item in input().split()]
    if row == 0 and col == 0:
        break
    land = []
    land.append([item for item in Sentinel * row + Sentinel * 2])
    for lp in range(col):
        part = [item for item in eval(input())]
        land.append([])
        land[-1].extend([Sentinel])
        land[-1].extend(part)
        land[-1].extend([Sentinel])
    land.append([item for item in Sentinel * row + Sentinel * 2])
    result = Labeling(land)
    print(result)

def Labeling(terrain):
    label = terrain
    offset = [[-1, 0], [0, -1], [1, 0], [0, 1]]
    signs = ["@", "#", "*"]
    rowLength, colLength = len(label) - 1, len(label[0]) - 1
    step = 0
    for row in range(1, rowLength):
        for col in range(1, colLength):
            mark = label[row][col]
            if mark in signs:
                pointStack = [[row, col]]
                label[row][col] = step
                while 0 < len(pointStack):
                    rowIndex, colIndex = pointStack.pop()
                    for x, y in offset:
                        offsetRow, offsetCol = rowIndex + x, colIndex + y
                        if label[offsetRow][offsetCol] == mark:
                            pointStack.append([offsetRow, offsetCol])
                            label[offsetRow][offsetCol] = step
                step += 1
    return step


Sentinel = "1"
while True:
    col, row = [int(item) for item in input().split()]
    if row == 0 and col == 0:
        break
    land = []
    land.append([item for item in Sentinel * row + Sentinel * 2])
    for lp in range(col):
        part = [item for item in eval(input())]
        land.append([])
        land[-1].extend([Sentinel])
        land[-1].extend(part)
        land[-1].extend([Sentinel])
    land.append([item for item in Sentinel * row + Sentinel * 2])
    result = Labeling(land)
    print(result)

+    rowLength, colLength = len(label) - 1, len(label[0]) - 1 -    for row in range(1, len(label) - 1): -        for col in range(1, len(label[row]) - 1): +    for row in range(1, rowLength): +        for col in range(1, colLength):