#include<iostream>
using namespace std;

#define INV '.'

void PropDistribute(char **map, int i, int j, char fruit){
	int di[] = {1,0,-1,0};
	int dj[] = {0,1,0,-1};

	if( map[i][j] != fruit ) return ;
	map[i][j] = INV;
	
	for(int u = 0; u < sizeof(di)/sizeof(*di); ++u){
		PropDistribute(map, i+di[u], j+dj[u], fruit);
	}

	return ;
}
int main(void){
	while( true ){
		int cnt = 0; // answer
		int H, W;
		char **map;
		
		cin >> H >> W;
		if( !H && !W ) break;

		map = new char*[H+2];
		for(int i = 0; i < H+2; ++i){
			map[i] = new char[W+2];
		}

		// init
		for(int i = 0; i < H+2; ++i){
			for(int j = 0; j < W+2; ++j){
				map[i][j] = INV;
			}
		}

		// input
		cin.ignore();
		for(int i = 1; i < H+1; ++i){
			for(int j = 1; j < W+1; ++j){
				cin >> map[i][j];
			}
			cin.ignore();
		}

		for(int i = 1; i < H+1; ++i){
			for(int j = 1; j < W+1; ++j){
				if( map[i][j] != INV ){
					cnt++;
					PropDistribute(map, i, j, map[i][j]);
				}
			}
		}

		cout << cnt << '\n';

		for(int i = 0; i < H+2; i++){
			delete [] map[i];
		}
		delete [] map;
	}
	return 0;
}