#include <stdio.h>

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

bool paint(int i,int j){
	if(data==' ')return false;
	
	if(i>0&&map[i][j]==map[i-1][j])paint(i-1,j);
	if(j>0&&map[i][j]==map[i][j-1])paint(i,j-1);
	if(i<=H&&map[i][j]==map[i+1][j])paint(i+1,j);
	if(i<=W&&map[i][j]==map[i][j+1])paint(i,j+1);
	return true;
}

int main(){
	int num=0;
	
	scanf("%d %d",&H,&W);
	for(int i=0;i<W;i++){
		scanf("%s",map[i];
	}
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(paint(i,j))num++;
		}
	}

	printf("%d\n",num);
	return 0;
}