#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int M=500;
int res,ans;
char a[M][M];
bool vis[M][M];
void func(int x,int y)
{
	vis[x][y]=true;
	if(a[x][y+1]==a[x][y]&&(!vis[x][y+1])) func(x,y+1);
	if(a[x+1][y]==a[x][y]&&(!vis[x+1][y])) func(x+1,y);
	if(a[x][y-1]==a[x][y]&&(!vis[x][y-1])) func(x,y-1);
	if(a[x-1][y]==a[x][y]&&(!vis[x-1][y])) func(x-1,y);
	res=1;	
	return;
}
int main()
{
	int h,l;
	while(~scanf("%d%d",&l,&h)){
		if(h==0) return 0;
	for(int j=1;j<=l;j++)
	{
		getchar();
		for(int i=1;i<=h;i++)	a[j][i]=getchar();
	}
	for(int j=1;j<=l;j++)
	{
		for(int i=1;i<=h;i++)
		{
			if(!vis[i][j]) func(i,j);
			ans+=res,res=0;
		}
	}
	printf("%d\n",ans);
	memset(a,0,sizeof(a));
	memset(vis,0,sizeof(vis));
	res=ans=0;
	}
}