Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# @????????? #?????? *?????????

import sys

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)

    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

        # for dy in range(-1,1):
        #     ny = y + dy
        #     # if 0 <= ny and ny < W and field[x][ny] == fru:
        #     if field[x][ny] == fru:
        #         dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] == '@':
                dfs(i,j,'@')
                count+=1
            elif field[i][j] == '#':
                dfs(i,j,'#')
                count+=1
            elif field[i][j] == '*':
                dfs(i,j,'*')
                count+=1
    print(count)

#x,y??§2??¶?????°???1?????§??\????????????????????\???????????°?????§????????¨???
# H,W=[int(i) for i in input().split()]
# H, W = int(input()).split()
while(True):
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        sys.exit()
    field = [] # ????¨??????¨??????
    for i in range(H):
        field.append(list(input()))
    solv(H,W)

Fixed submission:
# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(10000000)

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] != '.':
                dfs(i,j,field[i][j])
                count+=1
            # elif field[i][j] == '#':
            #     dfs(i,j,'#')
            #     count+=1
            # elif field[i][j] == '*':
            #     dfs(i,j,'*')
            #     count+=1
    print(count)

f = 0
while(f == 0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨?????????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f = 1

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys

def dfs(x, y, fru):
    field[x][y] = '.'
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)

    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] == '@':
                dfs(i,j,'@')
                count+=1
            elif field[i][j] == '#':
                dfs(i,j,'#')
                count+=1
            elif field[i][j] == '*':
                dfs(i,j,'*')
                count+=1
    print(count)

while(True):
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        sys.exit()
    field = []
    for i in range(H):
        field.append(list(input()))
    solv(H,W)

Fixed submission:
# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(10000000)

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] != '.':
                dfs(i,j,field[i][j])
                count+=1
            # elif field[i][j] == '#':
            #     dfs(i,j,'#')
            #     count+=1
            # elif field[i][j] == '*':
            #     dfs(i,j,'*')
            #     count+=1
    print(count)

f = 0
while(f == 0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨?????????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f = 1

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys

def dfs(x, y, fru):
    field[x][y] = '.'
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] == '@':
                dfs(i,j,'@')
                count+=1
            elif field[i][j] == '#':
                dfs(i,j,'#')
                count+=1
            elif field[i][j] == '*':
                dfs(i,j,'*')
                count+=1
    print(count)
while(True):
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        sys.exit()
    field = []
    for i in range(H):
        field.append(list(input()))
    solv(H,W)

Fixed submission:
# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(10000000)

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] != '.':
                dfs(i,j,field[i][j])
                count+=1
            # elif field[i][j] == '#':
            #     dfs(i,j,'#')
            #     count+=1
            # elif field[i][j] == '*':
            #     dfs(i,j,'*')
            #     count+=1
    print(count)

f = 0
while(f == 0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨?????????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f = 1

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# @????????? #?????? *?????????
import sys

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < W and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < H and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] == '@':
                dfs(i,j,'@')
                count+=1
            elif field[i][j] == '#':
                dfs(i,j,'#')
                count+=1
            elif field[i][j] == '*':
                dfs(i,j,'*')
                count+=1
    print(count)

#x,y??§2??¶?????°???1?????§??\????????????????????\???????????°?????§????????¨???
while(True):
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        sys.exit()
    field = [] # ????¨??????¨??????
    for i in range(H):
        field.append(list(input()))
    solv(H,W)

Fixed submission:
# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(10000000)

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] != '.':
                dfs(i,j,field[i][j])
                count+=1
            # elif field[i][j] == '#':
            #     dfs(i,j,'#')
            #     count+=1
            # elif field[i][j] == '*':
            #     dfs(i,j,'*')
            #     count+=1
    print(count)

f = 0
while(f == 0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨?????????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f = 1

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# @????????? #?????? *?????????

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] == '@':
                dfs(i,j,'@')
                count+=1
            elif field[i][j] == '#':
                dfs(i,j,'#')
                count+=1
            elif field[i][j] == '*':
                dfs(i,j,'*')
                count+=1
    print(count)

#x,y??§2??¶?????°???1?????§??\????????????????????\???????????°?????§????????¨???
f=0
while(f==0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨??????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f=1

Fixed submission:
# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(10000000)

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] != '.':
                dfs(i,j,field[i][j])
                count+=1
            # elif field[i][j] == '#':
            #     dfs(i,j,'#')
            #     count+=1
            # elif field[i][j] == '*':
            #     dfs(i,j,'*')
            #     count+=1
    print(count)

f = 0
while(f == 0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨?????????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f = 1

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(1500)
def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] == '@':
                dfs(i,j,'@')
                count+=1
            elif field[i][j] == '#':
                dfs(i,j,'#')
                count+=1
            elif field[i][j] == '*':
                dfs(i,j,'*')
                count+=1
    print(count)

#x,y??§2??¶?????°???1?????§??\????????????????????\???????????°?????§????????¨???
f=0
while(f==0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨??????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f=1

Fixed submission:
# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(10000000)

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] != '.':
                dfs(i,j,field[i][j])
                count+=1
            # elif field[i][j] == '#':
            #     dfs(i,j,'#')
            #     count+=1
            # elif field[i][j] == '*':
            #     dfs(i,j,'*')
            #     count+=1
    print(count)

f = 0
while(f == 0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨?????????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f = 1

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(2000)

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] == '@':
                dfs(i,j,'@')
                count+=1
            elif field[i][j] == '#':
                dfs(i,j,'#')
                count+=1
            elif field[i][j] == '*':
                dfs(i,j,'*')
                count+=1
    print(count)

#x,y??§2??¶?????°???1?????§??\????????????????????\???????????°?????§????????¨???
f=0
while(f==0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨??????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f=1

Fixed submission:
# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(10000000)

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] != '.':
                dfs(i,j,field[i][j])
                count+=1
            # elif field[i][j] == '#':
            #     dfs(i,j,'#')
            #     count+=1
            # elif field[i][j] == '*':
            #     dfs(i,j,'*')
            #     count+=1
    print(count)

f = 0
while(f == 0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨?????????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f = 1

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(10000)

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] == '@':
                dfs(i,j,'@')
                count+=1
            elif field[i][j] == '#':
                dfs(i,j,'#')
                count+=1
            elif field[i][j] == '*':
                dfs(i,j,'*')
                count+=1
    print(count)

#x,y??§2??¶?????°???1?????§??\????????????????????\???????????°?????§????????¨???
f=0
while(f==0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨??????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f=1

Fixed submission:
# coding: utf-8
# @????????? #?????? *?????????
import sys
sys.setrecursionlimit(10000000)

def dfs(x, y, fru):
    # ???????????¨?????????.???????????????
    field[x][y] = '.'
    # 4??????????????????
    for dx in [-1,0,1]:
        nx = x + dx
        if 0 <= nx and nx < H and field[nx][y] == fru:
            dfs(nx,y,fru)
    for dy in [-1,0,1]:
        ny = y + dy
        if 0 <= ny and ny < W and field[x][ny] == fru:
            dfs(x,ny,fru)

def solv(H,W):
    count = 0
    for i in range(H):
        for j in range(W):
            if field[i][j] != '.':
                dfs(i,j,field[i][j])
                count+=1
            # elif field[i][j] == '#':
            #     dfs(i,j,'#')
            #     count+=1
            # elif field[i][j] == '*':
            #     dfs(i,j,'*')
            #     count+=1
    print(count)

f = 0
while(f == 0):
    H, W = map(int, input().split())
    if H != 0 and W != 0:
        field = [] # ????¨??????¨?????????
        for i in range(H):
            field.append(list(input()))
        solv(H,W)
    else:
        f = 1