#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int h, w;
int dx[4] = {1, 0, -1,  0};
int dy[4] = {0, 1,  0, -1};
char **data;

//fType:WKO fruit now
void dfs(int x, int y, char fType)
{
	data[y][x] = 0;

	int i=0;
	for (i=0; i<4; i++) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (nx>=0 && nx<w && ny>=0 && ny<h && data[ny][nx]==fType)
			dfs(nx, ny, fType);
	}
}

int main()
{
	while (1) {
		int res;
		int i, j;

		//jnput
		scanf("%d%d ", &h, &w);
		if (!h && !w) break;

		//Allocate memory
		data = (char **)calloc(h, sizeof(char *));
		for (i=0; i<h; i++)
			data[i] = (char *)calloc(w, sizeof(char));

		for (i=0; i<h; i++)
			for (j=0; j<w; j++)
			scanf("%c ", &(data[i][j]));

		//dfs
		res = 0;
		for (i=0; i<h; i++)
			for (j=0; j<w; j++)
				if (data[i][j]) {
					dfs(j, i, data[i][j]);
					res++;
				}

		//output
		printf("%d\n", res);

		//Free memory
		for (i=0; i<h; i++)
			free(data[i]); 
		free(data);
	}




	return 0;
}