#include<iostream>
#include<cstdio>

using namespace std;

char field[110][110];
int N, M, ans = 0;
int dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };

void dfs(int x, int y)
{
	char c;
	c = field[x][y];
	field[x][y] = '%';
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dx[i], ny = y + dy[i];
		if (nx >= 0 && nx <= N && ny >= 0 && ny <= M && field[nx][ny] == c)
			dfs(nx, ny);
	}
}

void solve()
{
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			if (field[i][j] != '%')
			{
				dfs(i, j);
				ans++;
			}
		}
	}
	cout << ans << endl;
}

int main()
{
	while (1)
	{
		cin >> N >> M;
		if (!N && !M)
			break;
		for (int i = 0; i < N; i++)
			for (int j = 0; j < M; j++)
				cin >> field[i][j];
		solve();
		ans = 0;
	}

	return 0;
}
