#include	<iostream>
#include	<queue>
#include	<utility>

using namespace std;
typedef pair<int, int> P;

bool isInside(int oH, int oW, int tH, int tW) {
	if(0 <= tH && tH < oH && 0 <= tW && tW < oW) { return true; }
	return false;
}

int main(void) {
	queue< P > cds;
	char Maps[100][100], info;
	int count, oH, oW, sH, sW;
	const char vecX[4] = {1, 0, -1, 0}, vecY[4] = {0, 1, 0, -1};
	
	while(1) {
		cin >> oH >> oW;
		if(oH == 0 && oW == 0) break;
		
		count = 0;
		for(int i = 0; i < oH; i++)
			for(int j = 0; j < oW; j++)
				cin >> Maps[i][j];
		for(int i = 0; i < oH; i++) {
			for(int j = 0; j < oW; j++) {
				if(Maps[i][j] == '0') { continue; }
				info = Maps[i][j]; cds.push( P(i, j) ); count++;
				while( cds.size() ) {
					P ax = cds.front();
					cds.pop();
					Maps[ax.first][ax.second] = '0';
					for(int v = 0; v < 4; v++) {
						sH = ax.first + vecY[v]; sW = ax.second + vecX[v];
						if( isInside(oH, oW, sH, sW) ) {
							if (Maps[sH][sW] == info) cds.push( P(sH, sW) );
						}
					}
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}