#include<bits/stdc++.h>
using namespace std;
const int N=105;
int G[N][N],n,m,ans;
bitset<N> vis[N];
const int move[4][2]={
	{0,1},{0,-1},{1,0},{-1,0}	
};
inline int nextChar(void){
	char ch=getchar();
	while(ch!='#'&&ch!='*'&&ch!='@')
		ch=getchar();
	return ch;
}
inline void putInt(int tmp){
	int stk[10],tail=0;
	while(tmp)
		stk[tail++]=tmp%10,tmp/=10;
	for(int i=tail-1;i>=0;i--)
		putchar('0'+stk[i]);
	puts("");
}
void dfs(int x,int y,int k){
	if(x<1||x>n||y<1||y>n||G[x][y]!=k||vis[x][y])
		return;
	vis[x][y]=1;
	for(int i=0;i<4;i++)
		dfs(x+move[i][0],y+move[i][1],k);
}
signed main(void){
	while(scanf("%d%d",&n,&m)&&n){
		memset(G,0,sizeof(G)),ans=0;
		for(int i=1;i<=n;vis[i++].reset())
			for(int j=1;j<=m;j++)
				switch(nextChar()){
					case('#'):G[i][j]=1;break;
					case('*'):G[i][j]=2;break;
					case('@'):G[i][j]=3;break;
				}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				if(!vis[i][j])
					dfs(i,j,G[i][j]),ans++;
		putInt(ans);
	}
}