#include<iostream>
using namespace std;
#define LP(i,N) for(int i=0;i<N;i++)
#define MAX 100
int H,W;
char map[MAX+1][MAX+1];
int dx[]={ 0, 1, 0,-1};
int dy[]={-1, 0, 1, 0};
int count;
void print(){
	cout<<"--------------"<<endl;
	LP(i,H){
		LP(j,W)cout<<map[i][j];
		cout<<endl;
	}
}
void dfs(int h,int w,char fruit){
	if(h<0||w<0||h>=H||w>=W||map[h][w]=='0')return ;
	fruit=map[h][w];
	map[h][w]='0';
	LP(i,4){
		if(h+dy[i]<0||w+dx[i]<0||h+dy[i]>=W||w+dx[i]>=H||fruit!=map[h+dy[i]][w+dx[i]])continue;
		dfs(h+dy[i],w+dx[i],fruit);
	}
	return ;
}

int
main(){
	while(cin>>H>>W&&(H||W)){
		count=0;
		LP(i,H){
			LP(j,W)cin>>map[i][j];
		}
		LP(i,H){
			LP(j,W)
			if(map[i][j]!='0'){
				count++;
				dfs(i,j,map[i][j]);
			}
		}
		cout<<count<<endl;
	}
	return 0;
}