//Red and Black
#include<iostream>
#include<stdlib.h>
#include<queue>
using namespace std;
const int MAX_M = 100;
int W, H;
char rect[MAX_M][MAX_M];
int res[10000];
int counts = 0;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { -1,0,1,0 };
void solve(int sx, int sy,char vp) {
	rect[sx][sy] = 'X';
	
	for (int i = 0; i<4; i++) {

		int nx = sx + dx[i];
		int ny = sy + dy[i];
		if (nx >= 0 && nx < W&&ny >= 0 && ny < H&&rect[nx][ny] == vp)
			solve(nx, ny,rect[nx][ny]);
	}

}
int main() {
	while (true) {
		cin >> W >> H;
		if (W == 0 || H == 0)
			break;
		for (int i = 0; i < W; i++)
			for (int j = 0; j < H; j++)
				cin >> rect[i][j];
		for(int i=0;i<W;i++)
			for (int j = 0; j < H; j++) {
				if (rect[i][j] != 'X') {
					solve(i, j, rect[i][j]);
					res[counts]++;
				}
			}
		for (int i = 0; i < W; i++)
			for (int j = 0; j < H; j++)
				rect[i][j] = '\0';
		counts++;
	}
	for (int i = 0; i < counts; i++) {
		cout << res[i] << endl;
	}
	
	return 0;
}
