#include<stdio.h>
int a,b;
char c;
int dx[4]={ 0, 0, 1, -1 };
int dy[4]={ 1, -1, 0, 0 };
char field[101][101];
void dfs(int x,int y)
{
	field[x][y]='!';
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dx[i], ny = y + dy[i];
		if (0 <= nx&&nx < a && 0 <= ny&&ny < b&&field[nx][ny] ==c)dfs(nx, ny);
	}
}
int main()
{
	int res;
	while(scanf("%d %d",&a,&b)!=EOF&&(a+b)!=0)
	{
		while (getchar()!= '\n')continue;
		for(int i=0;i<a;i++)
		{
			scanf("%s",&field[i]);
		}
			res=0;
			for(int i=0;i<a;i++)
			{
				for(int j=0;j<b;j++)
				{
					if(field[i][j]!='!')
					{c=field[i][j];
					res++;
					dfs(i,j);
					}
				}
			}
			printf("%d\n",res);	
	}
	return 0;
}

