#include <cstdio>

char table[100][100];
int H, W;

void recA(int i, int j){
	table[i][j] = ' ';
	if(table[i-1][j] == '@' && i - 1 > 0) recA(i - 1, j);
	if(table[i+1][j] == '@' && i + 1 < H) recA(i + 1, j);
	if(table[i][j-1] == '@' && j - 1 > 0) recA(i, j - 1);
	if(table[i][j+1] == '@' && j + 1 < W) recA(i, j + 1);
	return;
}
void recB(int i, int j){
	table[i][j] = ' ';
	if(table[i-1][j] == '#' && i - 1 > 0) recB(i - 1, j);
	if(table[i+1][j] == '#' && i + 1 < H) recB(i + 1, j);
	if(table[i][j-1] == '#' && j - 1 > 0) recB(i, j - 1);
	if(table[i][j+1] == '#' && j + 1 < W) recB(i, j + 1);
	return;
}
void recC(int i, int j){
	table[i][j] = ' ';
	if(table[i-1][j] == '*' && i - 1 > 0) recC(i - 1, j);
	if(table[i+1][j] == '*' && i + 1 < H) recC(i + 1, j);
	if(table[i][j-1] == '*' && j - 1 > 0) recC(i, j - 1);
	if(table[i][j+1] == '*' && j + 1 < W) recC(i, j + 1);
	return;
}

int main(){
	int count = 0;
	
	scanf("%d %d", &H, &W);
	for(int i = 0; i < H; i++){
		scanf("%s", table[i]);
	}
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(table[i][j] == ' ') continue;
			if(table[i][j] == '@') recA(i, j);
			else if(table[i][j] == '#') recB(i, j);
			else if(table[i][j] == '*') recC(i, j);
			count++;
		}
	}
	
	printf("%d\n", count);
	return 0;
}