//POJ 1979 穷竭搜索
#include<stdio.h>
#include<stack>
#include<string.h>
using namespace std;
const int maxn = 105;
char g[maxn][maxn];
bool flag = true;
int n,m;
int ans;
struct Node{
	int x;
	int y;
	Node(int xx,int yy):x(xx),y(yy){
	}
	Node(){
	}
	void set(int xx,int yy){
		x = xx;y=yy;
	}
};
stack<Node> s;
Node begin;
void init(){
	char tmp;
	memset(g,'a',sizeof(g));
	scanf("%d%d",&n,&m);
	if(n==0&&m==0){
		flag = false;
		return;
	}
			scanf("%c",&tmp);
	for(int i = 1;i<=n;++i){
		for(int j = 1;j<=m;++j){
			scanf("%c",&g[i][j]);
		}
			scanf("%c",&tmp);
	}
//	printf("init finished\n");
}
inline void push(Node w,char x){
	g[w.x][w.y] = 'a';
	if(g[w.x][w.y+1]==x){
		g[w.x][w.y+1] = 'a';
		s.push(Node(w.x,w.y+1));
	}
	if(g[w.x][w.y-1]==x){
		g[w.x][w.y-1] = 'a';
		s.push(Node(w.x,w.y-1));
	}
	if(g[w.x+1][w.y]==x){
		g[w.x+1][w.y] = 'a';
		s.push(Node(w.x+1,w.y));
	}
	if(g[w.x-1][w.y]==x){
		g[w.x-1][w.y] = 'a';
		s.push(Node(w.x-1,w.y));
	}
}
int solve(){
	ans = 0;
	s = stack<Node>();
	for(int i = 1;i<=n;++i){
		for(int j = 1;j<=m;++j){
		if(g[i][j]=='a')continue;
		begin.set(i,j);
		s.push(begin);
		char lp = g[i][j];
		while(!s.empty()){
			Node work = s.top();
			//printf("%d,%d:%c\n",work.x,work.y,g[work.x][work.y]);
	//	printf("now: %d , %d\n",work.x,work.y);
			s.pop();
			push(work,lp);		
	}
	++ans;
	}
	}
}
int main(){
	while(true){
	init();
	if(!flag)break;
	solve();
	printf("%d\n",ans);
	}
	return 0;
}
