#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const int MAX_N = 50;
int N,M;
int mymap[MAX_N][MAX_N];
int ans;
int sum; 
int fx[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
void dfs(int x,int y,char zf){
	mymap[x][y] = '.';

	for(int i=0;i<4;i++){
		int nx = x+fx[i][0];
		int ny = y+fx[i][1];
		if(0<=nx && nx<N && 0<=ny && ny<M && mymap[nx][ny] == zf){
			dfs(nx,ny,zf);
		}
	}
	
	return ;
}
void solve(char zf){
	ans = 0;
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			if(mymap[i][j] == zf){
				ans++;
				dfs(i,j,zf);
			}
		}
	}
	sum+=ans;
}
int main()
{
	while(scanf("%d %d",&N,&M) != EOF,N&&M){
		sum=0;
		for(int i=0;i<N;i++){
			getchar();
			for(int j=0;j<M;j++)
				scanf("%c",&mymap[i][j]);	
		}
		solve('#');
		solve('@');
		solve('*');
		printf("%d\n",sum);
	}
	return 0;
}