h = w = 0

slist =[]

list1=[]

def dfs(f):

    while True:

        if len(slist) == 0:

            return 1

        coordinate= slist.pop()

        #print(coordinate)

        x = coordinate[0]

        y = coordinate[1]



        list1[y] = list1[y][:x] + '1' + list1[y][x + 1:]

        if x + 1 < w:

            if list1[y][x + 1] == f:

                slist.append([x + 1,y])

        if x - 1 >= 0:

            if list1[y][x-1] == f:

                slist.append([x - 1, y])

        if y + 1 < h:

            if list1[y + 1][x] == f:

                slist.append([x, y + 1])

        if y -1 >= 0:

            if list1[y -1][x] == f:

                slist.append([x, y - 1])



while True:

    h, w = list([int(x) for x in input().split(" ")])

    if 0 in (h, w):

        break

    n = 0

    for i in range(0, h):

        list1.append(eval(input()))

    for i in range(0, h):

        for j in range(0, w):

            if list1[i][j] != '1':

                slist.append([j,i])

                n += dfs(list1[i][j])

            #print(list1)

    print(n)

    list1=[]
import sys

sys.setrecursionlimit(20000)

h= 0

w = 0

list1 = []



def dfs(x, y, f):

    list1[y] = list1[y][:x] + '1' + list1[y][x+1:]



    if y - 1 >= 0:

        if list1[y - 1][x] == f:

            dfs(x, y - 1, f)

    if y + 1 < h:

        if list1[y + 1][x] == f:

            dfs(x, y + 1, f)

    if x - 1 >= 0:

        if list1[y][x - 1] == f:

            dfs(x - 1, y, f)

    if x + 1 < w:

        if list1[y][x + 1] == f:

            dfs(x + 1, y, f)

    return



while True:

    h, w = list([int(x) for x in input().split(" ")])

    if 0 in (h, w):

        break

    n = 0

    for i in range(0, h):

        list1.append(eval(input()))

    for i in range(0, h):

        for j in range(0, w):

            if list1[i][j] != '1':

                dfs(j, i, list1[i][j])

                n+=1

    print(n)

    list1=[]
h = w = 0
slist = []
list1 = []


def dfs(f):
    while True:
        if len(slist) == 0:
            return 1
        coordinate = slist.pop()
        # print(coordinate)
        x = coordinate[0]
        y = coordinate[1]
        list1[y] = list1[y][:x] + "1" + list1[y][x + 1 :]
        if x + 1 < w:
            if list1[y][x + 1] == f:
                slist.append([x + 1, y])
        if x - 1 >= 0:
            if list1[y][x - 1] == f:
                slist.append([x - 1, y])
        if y + 1 < h:
            if list1[y + 1][x] == f:
                slist.append([x, y + 1])
        if y - 1 >= 0:
            if list1[y - 1][x] == f:
                slist.append([x, y - 1])


while True:
    h, w = list([int(x) for x in input().split(" ")])
    if 0 in (h, w):
        break
    n = 0
    for i in range(0, h):
        list1.append(eval(input()))
    for i in range(0, h):
        for j in range(0, w):
            if list1[i][j] != "1":
                slist.append([j, i])
                n += dfs(list1[i][j])
            # print(list1)
    print(n)
    list1 = []

import sys

sys.setrecursionlimit(20000)
h = 0
w = 0
list1 = []


def dfs(x, y, f):
    list1[y] = list1[y][:x] + "1" + list1[y][x + 1 :]
    if y - 1 >= 0:
        if list1[y - 1][x] == f:
            dfs(x, y - 1, f)
    if y + 1 < h:
        if list1[y + 1][x] == f:
            dfs(x, y + 1, f)
    if x - 1 >= 0:
        if list1[y][x - 1] == f:
            dfs(x - 1, y, f)
    if x + 1 < w:
        if list1[y][x + 1] == f:
            dfs(x + 1, y, f)
    return


while True:
    h, w = list([int(x) for x in input().split(" ")])
    if 0 in (h, w):
        break
    n = 0
    for i in range(0, h):
        list1.append(eval(input()))
    for i in range(0, h):
        for j in range(0, w):
            if list1[i][j] != "1":
                dfs(j, i, list1[i][j])
                n += 1
    print(n)
    list1 = []

-h = w = 0 -slist = [] +import sys + +sys.setrecursionlimit(20000) +h = 0 +w = 0 -def dfs(f): -    while True: -        if len(slist) == 0: -            return 1 -        coordinate = slist.pop() -        # print(coordinate) -        x = coordinate[0] -        y = coordinate[1] -        list1[y] = list1[y][:x] + "1" + list1[y][x + 1 :] -        if x + 1 < w: -            if list1[y][x + 1] == f: -                slist.append([x + 1, y]) -        if x - 1 >= 0: -            if list1[y][x - 1] == f: -                slist.append([x - 1, y]) -        if y + 1 < h: -            if list1[y + 1][x] == f: -                slist.append([x, y + 1]) -        if y - 1 >= 0: -            if list1[y - 1][x] == f: -                slist.append([x, y - 1]) +def dfs(x, y, f): +    list1[y] = list1[y][:x] + "1" + list1[y][x + 1 :] +    if y - 1 >= 0: +        if list1[y - 1][x] == f: +            dfs(x, y - 1, f) +    if y + 1 < h: +        if list1[y + 1][x] == f: +            dfs(x, y + 1, f) +    if x - 1 >= 0: +        if list1[y][x - 1] == f: +            dfs(x - 1, y, f) +    if x + 1 < w: +        if list1[y][x + 1] == f: +            dfs(x + 1, y, f) +    return -                slist.append([j, i]) -                n += dfs(list1[i][j]) -            # print(list1) +                dfs(j, i, list1[i][j]) +                n += 1