#include <iostream>
#include <vector>

using namespace std;

int H, W;
int move_x[4] = {-1, 0, 0, 1};
int move_y[4] = {0, -1, 1, 0};
vector< vector<char> > Field;

void DFS(int y, int x, int c)
{
	Field[y][x] = '.';
	for(int i = 0; i < 4; ++i)
	{
		int nx = x + move_x[i];
		int ny = y + move_y[i];
		if(0 <= nx && nx < W && 0 <= ny && ny < H && Field[ny][nx] == c)
		{
			DFS(ny, nx, c);
		}
	}
}

void solve()
{
	while(cin >> H >> W, H || W)
	{
		int count = 0;
		Field.resize(H);
		for(int i = 0; i < H; ++i)
		{
			Field[i].resize(W);
			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] != '.')
				{
					++count;
					char c = Field[i][j];
					DFS(i, j, c);
				}
			}
		}
		cout << count << endl;
	}
}

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