#include <iostream>
#include <vector>
#include <string>
#include <sstream>
//#include <fstream>

using namespace std;

bool dfs (int row, int col, char p, vector <string> d, vector <vector <bool> >& used )
{
	// order up right down left
	const int dir[][2] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };
	int size = d.size();
	int len  = d[0].size();
	int k;

	if (used[row][col] ){
		return false;
	} // end if

	used[row][col] = true;

	for (k = 0; k < 4; ++k){
		int nrow = row + dir[k][0];
		int ncol = col + dir[k][1];
		if (nrow < 0 || nrow >= size || ncol < 0 || ncol >= len ){
			continue;
		} // end if
		if (!used[nrow][ncol] && d[nrow][ncol] == p ){
			if (dfs (nrow, ncol, p, d, used )){
				return true;
			} // end if
		} // end if
	} // end for

	return false;
}

	
int main()
{
//	cut here before submit 
//	freopen ("testcase.property", "r", stdin );
	string str = "";
	int h, w;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> h >> w;
		
		if (h == 0 && w == 0 ){
			break;
		} // end if
		
		vector <string> d (h, string (w, ' ') );

		int i,j;

		for (i = 0; i < h; ++i){
			getline (cin, str );
			for (j = 0; j < w; ++j){
				d[i][j] = str[j];
			} // end for
		} // end for

		vector <vector <bool> > used (h, vector <bool> (w, false ) ); 

		int res = 0;
		
		for (i = 0; i < h; ++i){
			for (j = 0; j < w; ++j){
				vector <vector <bool> > pre = used;
				dfs (i, j, d[i][j], d, used );
				if (pre != used ){
					++res;
				} // end if
			} // end for
		} // end for

		cout << res << endl;	

	} // end loop

		
	return 0;
}