#include <stdio.h>

int n1;
int n2;
char s[100][100];
int b[100][100];
int ans;

void func(int x, int y) {
	if (x != 0 && s[x][y] == s[x - 1][y] && b[x - 1][y] == 0) {
		b[x - 1][y] = 1;
		func(x - 1, y);
	}
	if (x != n1 - 1 && s[x][y] == s[x + 1][y] && b[x + 1][y] == 0) {
		b[x + 1][y] = 1;
		func(x + 1, y);
	}
	if (y != 0 && s[x][y] == s[x][y - 1] && b[x][y - 1] == 0) {
		b[x][y - 1] = 1;
		func(x, y - 1);
	}
	if (y != n2 - 1 && s[x][y] == s[x][y + 1] && b[x][y + 1] == 0) {
		b[x][y + 1] = 1;
		func(x, y + 1);
	}
	return;
}

int main() {
	while (1) {
		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				s[i][j] = '!';
				b[i][j] = 0;
				ans = 0;
			}
		}
		scanf("%d", &n1);
		scanf("%d", &n2);
		if (n1 == 0 && n2 == 0) {
			break;
		}
		if (n1 == 0 || n2 == 0) {
			continue;
		}
		for (int i = 0; i < n1; i++) {
			scanf("%s", s[i], 100);
		}
		for (int i = 0; i < n1; i++) {
			for (int j = 0; j < 100; j++) {
				if (s[i][j] != '@' && s[i][j] != '#' && s[i][j] != '*' && s[i][j] != '!') {
					s[i][j] = '!';
				}
			}
		}
		for (int i = 0; i < n1; i++) {
			for (int j = 0; j < n2; j++) {
				if (b[i][j] == 1) {
					continue;
				}
				b[i][j] = 1;
				ans += 1;
				func(i, j);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}