#include <iostream>
#include <vector>
#include <string>

struct node{
	int x;
	int y;
	struct node* parent;

	node(): x(-1), y(-1), parent(nullptr)
	{}
};

struct node* get_root(struct node* p){
	if(p->parent == nullptr){
		return p;
	}else{
		return get_root(p->parent);
	}
}

void solve(int H, int W){
	std::string farm[H];
	node nodes[H*W];

	for(int i = 0; i < H; i++){
		std::cin >> farm[i];
		for(int j = 0; j < W; j++){
			int index = i*W + j;
			nodes[index].y = i;
			nodes[index].x = j;
		}
	}

	for(int y = 0; y < H; y++){
		for(int x = 0; x < W; x++){
			// up
			int y_u = y - 1;
			node* up_root = nullptr;
			bool up_found = y_u >= 0 && farm[y_u][x] == farm[y][x];
			if(up_found){
				up_root = get_root(&nodes[y_u*W + x]);
			}
			// left
			int x_l = x - 1;
			node* left_root = nullptr;
			bool left_found = x_l >= 0 && farm[y][x_l] == farm[y][x];
			if(left_found){
				left_root = get_root(&nodes[y*W + x_l]);
			}

			if(up_found && left_found == false){
				nodes[y*W + x].parent = up_root;
			}else if(left_found && up_found == false){
				nodes[y*W + x].parent = left_root;
			}else if(up_found && left_found){
				if(up_root != left_root){
					up_root->parent = left_root;
				}
				nodes[y*W + x].parent = left_root;
			}else{
				// no-op
			}
		}
	}

	int ans = 0;
	for(int i = 0; i < H*W; i++){
		ans += nodes[i].parent == nullptr ? 1 : 0;
	}

#if 0
	/*
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			printf("%2d ", get_root(&nodes[i*W + j])->i);
		}
		std::cout << std::endl;
	}*/
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(nodes[i*W + j].parent == nullptr){
			printf("root %d %d\n", i, j);
			}
		}
	}

#endif
	std::cout << ans << std::endl;
}

int main(){
	int H, W;

	while(true){
		std::cin >> H >> W;
		if(H == 0 && W == 0){
			break;
		}else{
			solve(H, W);
		}
	}
}

