#include<iostream>
using namespace std;
int H, W;
char maze[102][102];
int res = 0;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

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

int main()
{
	while (cin >> H >> W)
	{
		if (H == 0 && W == 0) break;
		res = 0;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cin >> maze[i][j];
			}
		}
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (maze[i][j] != '0')
				{
					res++;
					dfs(i, j, maze[i][j]);
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}
