#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;

char s[110][110];
int v[110][110];
int n,m;

void dfs(int x,int y,char c)
{
	v[x][y] = 1;
	int i,nx,ny;
	int xx[] = {0,0,1,-1};
	int yy[] = {1,-1,0,0};

	for(i = 0;i < 4;i++){
		nx=x+xx[i],ny=y+yy[i];
		if(nx>=0 && nx<n && ny>=0 && ny<m && s[nx][ny] == c && !v[nx][ny]){
			v[nx][ny] = 1;
			dfs(nx,ny,c);
		}
	}
}

int main()
{
	while(cin >> n >> m && n+m){
		memset(v,0,sizeof(v));
		int ans = 0,i,j,k;
		for(i = 0;i < n;i++)
			for(j = 0;j < m;j++)
				cin >> s[i][j];
		char c[]={'#','*','@'};
		for(k = 0;k < 3;k++)
		for(i = 0;i < n;i++)
			for(j = 0;j < m;j++)
				if(s[i][j] == c[k] && !v[i][j]){
					v[i][j] = 1;
					dfs(i,j,c[k]);
					ans++;
				}
				cout << ans << endl;
	}
	return 0;
}
