#include <iostream>
#include <string>
#include <cstring>
#define MAX 100
using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int mem[MAX][MAX];
int X, Y, num;
string map[MAX];

void dfs(int y, int x, char c) {
	if (x<0||y<0||x>=X||y>=Y) return;//out of range
	if (map[y][x] != c) return;//not explored, but differential char
	if (mem[y][x] != 0) return;//explored
	mem[y][x] = num;
	for (int i=0; i<4; i++)
		dfs(y+dy[i], x+dx[i], c);
}

int main() {
	while (cin >> Y >> X, X||Y) {
		num = 0;
		memset(mem, 0, sizeof(mem));
		for (int i=0; i<Y; i++)
			cin >> map[i];

		for (int y=0; y<Y; y++)
		for (int x=0; x<X; x++) {
			if (mem[y][x] != 0) continue;
			num++;
			dfs(y, x, map[y][x]);
		}

		cout << num << endl;
	}
	return 0;
}