#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;
char stage[128][128];
int w,h;
void dfs(int y,int x){
	char med = stage[y][x];
	stage[y][x] = '.';
	rep(i,4){
		if(stage[y+dy[i]][x+dx[i]] == med)dfs(y+dy[i],x+dx[i]);
	}
	return ;
}
int main(){
	while(scanf("%d%d",&h,&w), h|w){
		memset(stage,0,sizeof(stage));
		rep(i,h)scanf("%s",stage[i]);
		int res = 0;
		rep(i,h){
			rep(j,w){
				if(stage[i][j] != '.'){
					dfs(i,j);
					res++;
				}
			}
		}
		printf("%d\n",res);
	}
	return 0;
}