#include <bits/stdc++.h>
using namespace std;

string s[105];
int fa[100005];
int sum = 0;

void build(int qwq) {for(int i=1;i<=qwq;i++) fa[i]=i;sum = qwq;return ;}
int find(const int &x) {return fa[x]==x?x:fa[x]=find(fa[x]);}
bool che(const int &x,const int &y){return find(x)==find(y);}
void mer(const int &x,const int &y) {if(!che(x,y)){ fa[fa[x]]=fa[y];sum--;}return ;}

int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0&&m==0)break;
		build(n*m);
		for(int i=0;i<n;i++){
			cin>>s[i];
			for(int j=0;j<m;j++){
				if(i!=0&&s[i][j]==s[i-1][j])mer(i*m+j,(i-1)*m+j);
				if(j!=0&&s[i][j]==s[i][j-1])mer(i*m+j,i*m+j-1);
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}
