def infection(i, j,H, W, moji):
    if farm[i][j] == moji:
        farm[i][j] = '+'
        if j + 1 < W : infection(i, j + 1,H,W,moji)
        if i + 1 < H : infection(i + 1, j,H,W,moji)
        if j - 1 >= 0 :infection(i, j - 1,H,W,moji)
        if i - 1 >= 0 :infection(i - 1, j,H,W,moji)

while(1):
    farm = []
    cnt = 0
    H, W = list(map(int, input().split()))
    if H == 0 and W == 0: break

    for i in range(H):
        farm.append(list(input()))

    for i in range(H):
        for j in range(W):
            if farm[i][j] == '+': continue
            cnt += 1
            infection(i, j,H,W,moji)
    print(cnt)