#include<iostream>
#include<cstring>
using namespace std;
int n, m,map[150][150];
int bord[4][2] = { 1,0,-1,0,0,1,0,-1 };
char a[150][150];
void dfs(int x, int y,char z) {
	for (int i = 0; i < 4; i++) {
		int A = x + bord[i][0];
		int B = y + bord[i][1];
		if (A >= 0 && B >= 0 && A < n && B < m && map[A][B] == 0 && a[A][B] == z) {
			map[A][B] = 1;
			dfs(A, B, z);
		}
	}
}
int main() {
//#ifdef LOCAL
//	freopen("Text.txt", "r", stdin);
//#endif // DEBUG

	while (cin >> n >> m && n != 0 && m != 0) {
		memset(map, 0, sizeof(map));
		int people = 0;
		for (int i = 0; i < n; i++)
			for (int g = 0; g < m; g++)
				cin >> a[i][g];
		for (int i = 0; i < n; i++) {
			for (int g = 0; g < m; g++) {
				if (map[i][g] == 0) {
					people++;
					dfs(i, g, a[i][g]);
				}
			}
		}
		cout << people << endl;
	}
	return 0;
}
