#include<iostream> 
#include<cstring>
#include<cmath>
using namespace std;

const int MAX = 20;
int N, M;
char garden[MAX][MAX+1];
int num;

void dfs(int x, int y, char ch){
	garden[x][y] = '.';
	for(int dx = -1; dx <= 1; dx++){
		for(int dy = -1; dy <= 1; dy++){
			if(abs(dx) + abs(dy) > 1) continue;
			int nx = x + dx, ny = y + dy;
			if(nx >= 0 && nx < N && ny >= 0 && ny < M && garden[nx][ny] == ch) dfs(nx, ny, ch);
		}
	}
	return;
}

int main(){
	for(;;){
		cin >> N >> M;
		if(N == 0) break;
		memset(garden,'\0',sizeof(garden));
		for(int i = 0; i < N; i++)
			cin >> garden[i];
		num = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < M; j++){
				if(garden[i][j] != '.') {
					dfs(i,j,garden[i][j]);
					num++;
				}
			}
		}
		cout << num << endl;
	}
	return 0;
}

