import std.stdio, std.array, std.string, std.conv, std.algorithm;

int H, W;
auto dy = [0, 0, 1, -1], dx = [1, -1, 0, 0];
char[][] board;

void main(){
	for(;init;){
		writeln(solve);
	}
}

bool init(){
	auto input = map!(to!int)(readln.chomp.split);
	H = input[0];
	W = input[1];
	
	board = new char[][](H);
	foreach(ref line; board){
		line = to!(char[])(readln.chomp);
	}
	return H > 0;
}

int solve(){
	int ans = 0;
	foreach(y; 0..H){
		foreach(x; 0..W){
			if(board[y][x] != '.'){
				++ans;
				dfs(y, x, board[y][x]);
			}
		}
	}
	return ans;
}

void dfs(int y, int x, char col){
	board[y][x] = '.';
	foreach(k; 0..4){
		int ny = y + dy[k], nx = x + dx[k];
		if(0<=ny && ny<H && 0<=nx && nx<W && board[ny][nx] == col){
			dfs(ny, nx, col);
		}
	}
}