#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define Max 500
using namespace std;
const int mx[4]={0,-1,0,1};
const int my[4]={-1,0,1,0};
int h,w;
char mass[Max][Max];
int visited[Max][Max]{};
void DFS(int i,int j,char ch);
int main()
{
	char ch;
	int ans=0;
	while(cin>>h>>w){
		memset(visited,0,sizeof(visited));
		for(int i=0;i<h;i++)
		{
			scanf("%s",&mass[i]);
		}
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				if(visited[i][j]) continue;
				ch=mass[i][j];
				ans++;
				DFS(i,j,ch);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
void DFS(int i,int j,char ch)
{
	if(visited[i][j]) return;
	int x1,y1;
	visited[i][j]=1;
	for(int k=0;k<4;k++)
	{
		x1=i+mx[k];
		y1=j+my[k];
		if(0<=x1&&x1<h&&0<=y1&&y1<w&&mass[x1][y1]==ch)
		{
			DFS(x1,y1,ch);
		}
	}
	return ;
}
