#include <cstdio>
#define MAX_H 100
#define MAX_W 100

int H,W;
char field[MAX_H][MAX_W+1];
char tmp[2];

void dfs(int x,int y){
	field[x][y]='.';
	for(int dx = -1; dx <= 1; dx++){
		for (int dy = -1; dy <= 1; dy++){
			if(dx!=0&&dy!=0)continue;
			int nx = x + dx,ny = y + dy;
			if(0<=nx && nx<W && 0<=ny && ny<H && field[nx][ny] == tmp[0])
				dfs(nx,ny);
		}
	}
	return;
}

void solve(){
	int res = 0;
	for (int i = 0; i < W; i++){
		for (int j = 0; j < H; j++){
			if(field[i][j]!='.'){
				tmp[0] = field[i][j];
				dfs(i,j);
				res++;
			}
		}
	}
	printf("%d\n",res);
}

int main(){
	scanf("%d%d",&H,&W);
	while(H!=0&&W!=0){
		for (int i = 0; i < H; i++)
			scanf("%s",field[i]);
		solve();
		scanf("%d%d",&H,&W);
	}
	return 0;
}
