#include <iostream>
using namespace std;

const int MAX_W = 100, MAX_H = 100;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
int W, H;
int x, y;
char field[MAX_W][MAX_H];
bool check[MAX_W][MAX_H];
int result;

void dfs(int x, int y);
void solve();

int main(){
	while(1){
		result = 0;
		for(int i=0; i<MAX_W; i++){
			for(int j=0; j<MAX_H; j++){
				check[i][j] = true;
			}
		}

		cin >> H;
		cin >> W;
		if(W==0 && H==0) break;

		for(int i=0; i<H; i++){
			for(int j=0; j<W; j++){
				cin >> field[j][i];
			}
		}
		

		solve();
		cout << result << endl;
	}

	return 0;
}

void dfs(int x, int y){
	check[x][y] = false;

	for(int i=0; i<4; i++){
		int xnew = x + dx[i];
		int ynew = y + dy[i];

		if(0<=xnew && xnew<=W-1 && 0<=ynew && ynew<=H-1 && check[xnew][ynew] && field[x][y]==field[xnew][ynew]) dfs(xnew, ynew);
	}
}

void solve(){
	for(int i=0; i<W; i++){
		for(int j=0; j<H; j++){
			if(check[i][j]){
				dfs(i, j);
				result++;
			}
		}
	}
}