#include <iostream>
#include <vector>
using namespace std;
int X,Y;
char map[100][100];
bool used[100][100];
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

bool input(){
	cin >> X >> Y;
	if(X == 0 && Y == 0) return false;
	for(int i = 0;i < X;++i){
		for(int j = 0;j < Y;++j){
			cin >> map[i][j];
		}
	}
	fill(used[0],used[0]+100*100,false);
	return true;
}

void dfs(int sx,int sy,char symbol){
	used[sx][sy] = 1;
	for(int i = 0;i < 4;++i){
		int cx = sx + dx[i],cy = sy + dy[i];
		if(cx >= 0 && cy >= 0 && cx < X && cy < Y && !used[cx][cy] && map[cx][cy] == symbol){
			dfs(cx,cy,symbol);
		}
	}
}

int main(){
	while(input()){
		int res = 0;
		for(int i = 0;i < X;++i){
			for(int j  = 0;j < Y;++j){
				if(!used[i][j]){
					char crt = map[i][j];
					dfs(i,j,crt);
					++res;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}
