#include <iostream>
#include <cstdio>
using namespace std;

const int margin = 2;

bool check(int i, int j, char c, char table[128][128]) {
	if(table[i + margin][j + margin] != c || c == 0) {
		return false;
	}

	table[i + margin][j + margin] = 0;
	check(i + 1, j, c, table);
	check(i - 1, j, c, table);
	check(i, j + 1, c, table);
	check(i, j - 1, c, table);

	return true;
}

int main() {
	int H, W;

	while(cin >> H >> W, H | W) {
		char in[128][128] = {0};
		int ans = 0;
		for(int i = 0; i < H; i++) {
			scanf("%s", in[i + margin] + margin);
		}

		for(int i = 0; i < H; i++)
			for(int j = 0; j < W; j++) {
				if(check(i, j, in[i + margin][j + margin], in))
					ans++;
			}

		cout << ans << endl;
	}

	return 0;
}