#include <iostream>

using namespace std;

int M, N;

char nums[101][101];

int cnt = 0;

int dx[4] = {0, 0, 1, -1};

int dy[4] = {1, -1, 0, 0};

void dfs(int x, int y, char c) {
	if (nums[x][y] != c) {
		return;
	}
	nums[x][y] = '.';
	for (int i = 0; i < 4; i++) {
		int tx = dx[i] + x;
		int ty = dy[i] + y;
		if (tx >= 0 && tx < M && ty >= 0 && ty < N) {
			if (nums[tx][ty] == c)
				dfs(tx, ty, c);
		}
	}
}

int main() {
	while (true) {
		cin >> M;
		cin >> N;
		if (!M && !N) {
			break;
		}
		if (!M || !N) {
			cout << 0 << endl;
			continue;
		}
		for (int i = 0; i < M; i++) {
			for (int j = 0; j < N; j++) {
				cin >> nums[i][j];
			}
		}
		for (int i = 0; i < M; i++) {
			for (int j = 0; j < N; j++) {
				if (nums[i][j] != '.') {
					cnt++;
					dfs(i, j, nums[i][j]);
				}
			}
		}
		cout << cnt << endl;
		cnt = 0;
	}
	return 0;
}
