#include <iostream>
using namespace std;
int H,W;
char field[100][100];
void dfs(int,int);
int main(){
	while(true){
		int count = 0;
		cin>>H>>W;
		if(!(H+W))break;
		for (int i = 0; i < W; i++) {
			for (int j = 0; j < H; j++) {
				cin>>field[i][j];
			}
		}
		int a,b;
		for (int i = 0; i < W; i++) {
			for (int j = 0; j < H; j++) {
				if(field[i][j] != '.'){
					dfs(i,j);
					count++;
				}
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

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