#include<iostream>
using namespace std;
int N , M;
char room[100][100];
int next_step[4][2] = {
	{0 , 1} , {1 , 0} , {0 , -1} , {-1 , 0}
};
int number;
void dfs(const int &x , const int &y , const char c)
{
	room[x][y] = 'X';
	for(int i = 0 ; i < 4 ; i++)
	{
		int nx = x + next_step[i][0] , ny = y + next_step[i][1];
		if(nx >= 0 && nx < N && ny >= 0 && ny < M && room[nx][ny] == c)
		{
			dfs(nx , ny , c);
		}
	}
}
void solve()
{
	for(int i = 0 ; i < N ; i++)
		for(int j = 0 ; j < M ; j++)
		{
			if(room[i][j] != 'X')
			{
				dfs(i , j , room[i][j]);
				number++;
			}
		}
	cout << number;
}
int main(int argc, char const *argv[])
{
	while(cin >> M >> N, N != 0)
	{
	    number = 0;
		for(int i = 0 ; i < N ; i++)
			for(int j = 0 ; j < M ; j++)
			{
				cin >> room[i][j];
			}
		solve();
	}
	return 0;
}
