#include<iostream>
#define MAX_H 100
#define MAX_M 100
using namespace std;

int H, W;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
char field[MAX_H][MAX_M + 1];
const char t = 'T';
int ans = 0;

void dfs(int x, int y, char a)
{
	field[x][y] = t;
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dx[i], ny = y + dy[i];
		if (nx < H && ny < W && nx >= 0 && ny >= 0 && field[nx][ny] == a)
			dfs(nx, ny, a);
	}
}

void solve()
{
	while (true)
	{
		cin >> H >> W;
		if (!H && !W)
			break;
		for (int i = 0; i < H; i++)
			for (int j = 0; j < W; j++)
				cin >> field[i][j];
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (field[i][j] != t)
				{
					dfs(i, j, field[i][j]);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return 0;
}