


#define INF 1000000;
#define RE(i,n)  for(i=0;i<n;i++)
#include<algorithm>
#include<iostream>
#include<time.h>
using namespace std;
inline int max(int n1 = -1000000, int n2 = -1000000, int n3 = -1000000)
{
	return n1 > n2 ? (n1 > n3 ? n1 : n3) : (n2 > n3 ? n2 : n3);
}
inline int min(int n1 = 1000000, int n2 = 1000000, int n3 = 1000000)
{
	return n1 < n2 ? (n1 < n3 ? n1 : n3) : (n2 < n3 ? n2 : n3);
}
char flag=0;
int ans = 0;
int  dfs(int &ans,int i,int j,char map[105][105])
{
	if (map[i][j] == 0)
	{
		return 0;
	}
	else
	{
		if (flag == 0) { flag = map[i][j]; ans++; }
		else if (map[i][j] != flag) { return 0; }

		map[i][j] = 0;

		if (i == 0 && j == 0) { dfs(ans,i, j + 1, map); dfs(ans, i, j + 1, map); }
		else if (i == 0) {
			dfs(ans, i, j + 1, map); dfs(ans, i, j-1, map); dfs(ans,i+1, j, map);
		}
		else if (j == 0) { dfs(ans,i-1, j, map); dfs(ans,i+1, j, map);
		dfs(ans,i, j+1, map);}
		else { dfs(ans,i-1, j, map); dfs(ans,i+1, j, map);
		dfs(ans,i, j-1, map);
		dfs(ans,i, j+1, map);
		}
	}

	
}
//#define LOCAL
int main()
{
#ifdef LOCAL

freopen("C:\\Users\\VULCAN\\Desktop\\data.in", "r", stdin);
//	freopen("C:\\Users\\VULCAN\\Desktop\\data.out", "w", stdout);
#endif
//这是一条帅气的分界线，写程序从这里开始吧

int m, n;
while (cin >> m >> n, m)
{
	char map[105][105] = { 0 };
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> map[i][j];
		}
	}
	
	for(int i=0;i<m;i++)
		for (int j = 0; j < n; j++)
		{
			ans+=dfs(ans,i, j, map);
			flag = 0;
		}
	cout << ans;
}





//这是一条可爱的分界线
#ifdef LOCAL
printf("用时%.3f秒\n", (double)clock() / CLOCKS_PER_SEC);
#endif
return 0;
}





