#include <stack>
#include<vector>
#include<iostream>
using namespace std;

char mat[100][100];
int dx[4] = { 0, -1, 0, 1 };
int dy[4] = { -1, 0, 1, 0 };
int res = 0;
int row, col;
char a;

void dfs(int x, int y)
{
	a = mat[x][y];
	mat[x][y] = '.';
	int xx, yy;
	for (int i = 0; i < 4; i++)
	{
		xx = x + dx[i];
		yy = y + dy[i];
		if (xx >= 0 && xx < row && yy >= 0 && yy < col && mat[xx][yy] == a)
			dfs(xx, yy);
	}
}

int main() {

	while (true)
	{
		res = 0;
		scanf("%d %d", &row, &col);
		if (row == 0)
			break;
		getchar();
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < col; j++)
				scanf("%c", &mat[i][j]);
			getchar();
		}
		for (int i = 0; i < row; i++)
			for (int j = 0; j < col; j++)
				if(mat[i][j] != '.')
				{
					res++;
					dfs(i, j);
				}
		printf("%d\n", res);
	}
	return 0;
}
