def f(y,x,c0):

  M.append([y,x])

  while M:

    y,x=M.pop()

    if A[y][x]==c0:

      A[y][x]=' '

      for i,j in [[0,-1],[-1,0],[0,1],[1,0]]: M.append([y+i,x+j])

  return 1



M=[]

while 1:

  H,W=list(map(int,input().split()))

  if H==W==0: break

  A=[list(' '*(W+2)) for _ in range(H+2)]

  for i in range(H): A[i+1][1:W+1]=list(input())

  c=0

  for i in range(1,H+1):

    for j in range(1,W+1):

      c0=A[i][j]

      if c0!=' ': c+=f(i,j,c0)

  print(c)
def f(y,x,a):

  M.append([y,x])

  while M:

    y,x=M.pop()

    if A[y][x]==a:

      A[y][x]=' '

      for i,j in [[0,-1],[-1,0],[0,1],[1,0]]: M.append([y+i,x+j])

  return 1



M=[]

while 1:

  H,W=list(map(int,input().split()))

  if H==W==0: break

  A=[list(' '*(W+2)) for _ in range(H+2)]

  for i in range(H): A[i+1][1:W+1]=list(input())

  c=0

  for i in range(1,H+1):

    for j in range(1,W+1):

      a=A[i][j]

      if a!=' ': c+=f(i,j,a)

  print(c)
def f(y, x, c0):
    M.append([y, x])
    while M:
        y, x = M.pop()
        if A[y][x] == c0:
            A[y][x] = " "
            for i, j in [[0, -1], [-1, 0], [0, 1], [1, 0]]:
                M.append([y + i, x + j])
    return 1


M = []
while 1:
    H, W = list(map(int, input().split()))
    if H == W == 0:
        break
    A = [list(" " * (W + 2)) for _ in range(H + 2)]
    for i in range(H):
        A[i + 1][1 : W + 1] = list(input())
    c = 0
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            c0 = A[i][j]
            if c0 != " ":
                c += f(i, j, c0)
    print(c)

def f(y, x, a):
    M.append([y, x])
    while M:
        y, x = M.pop()
        if A[y][x] == a:
            A[y][x] = " "
            for i, j in [[0, -1], [-1, 0], [0, 1], [1, 0]]:
                M.append([y + i, x + j])
    return 1


M = []
while 1:
    H, W = list(map(int, input().split()))
    if H == W == 0:
        break
    A = [list(" " * (W + 2)) for _ in range(H + 2)]
    for i in range(H):
        A[i + 1][1 : W + 1] = list(input())
    c = 0
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            a = A[i][j]
            if a != " ":
                c += f(i, j, a)
    print(c)

-def f(y, x, c0): +def f(y, x, a): -        if A[y][x] == c0: +        if A[y][x] == a: -            c0 = A[i][j] -            if c0 != " ": -                c += f(i, j, c0) +            a = A[i][j] +            if a != " ": +                c += f(i, j, a)