#include <iostream>	

void DFS_rec(char** board, int** region, int count, int x, int y, char c, int H, int W)
{
	region[x][y] = count;
	if (x>0) {
		if (board[x-1][y] == c && region[x-1][y] == -1) DFS_rec(board, region, count, x-1, y, c, H, W);
	}
	if (x<H-1) {
		if (board[x+1][y] == c && region[x+1][y] == -1) DFS_rec(board, region, count, x+1, y, c, H, W);
	}
	if (y>0) {
		if (board[x][y-1] == c && region[x][y-1] == -1) DFS_rec(board, region, count, x, y-1, c, H, W);
	}
	if (y<W-1) {
		if (board[x][y+1] == c && region[x][y+1] == -1) DFS_rec(board, region, count, x, y+1, c, H, W);
	}
}

int DFS(char** board, int** region, int H, int W)
{
	int count = 0;
	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			if (region[i][j] >= 0) continue;
			char c = board[i][j];
			DFS_rec(board, region, count, i, j, c, H, W);
			count++;
		}
	}
	return count;
}

int main()
{
	int H, W;
	while (std::cin >> H >> W) {
		if (H==0) break;
	
		char** board = new char*[H];
		for (int i=0; i<H; i++) board[i] = new char[W];
		
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) std::cin >> board[i][j];
		}
		
		int** region = new int*[H];
		for (int i=0; i<H; i++) region[i] = new int[W];
		
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) region[i][j] = -1;
		}
		
		std::cout << DFS(board, region, H, W) << std::endl;
		
		for (int i=0; i<H; i++) delete[] board[i];
		delete[] board;
		for (int i=0; i<H; i++) delete[] region[i];
		delete[] region;
	}
	return 0;
}
	

