#include<iostream>
#include<cstring>
using namespace std;
char map[110][110];
int visited[110][110];
int num=0;
int a,b;
void dfs(int i,int j){
	if(visited[i][j]!=0)return;
	visited[i][j]=num;
	char ch=map[i][j];
	if(i+1<=a&&map[i+1][j]==ch)dfs(i+1,j);
	if(j+1<=b&&map[i][j+1]==ch)dfs(i,j+1);
	if(i-1>=1&&map[i-1][j]==ch)dfs(i-1,j);
	if(j-1>=1&&map[i][j-1]==ch)dfs(i,j-1);
}
int main(){
	cin>>a>>b; 
	while(a!=0&&b!=0){
		num=0;
		memset(visited,0,sizeof(visited));
		for(int i=1;i<=a;i++){
			for(int j=1;j<=b;j++){
				cin>>map[i][j];
			}
		}
		for(int i=1;i<=a;i++)
		for(int j=1;j<=b;j++){
			if(visited[i][j]==0){
				num++;dfs(i,j);
			}
		}
		cout<<num<<endl;
		cin>>a>>b;
	}
	return 0;
}
