#include<iostream>
using namespace std;

#define MAXSIZE 100

char Graph[MAXSIZE][MAXSIZE];
int visited[MAXSIZE][MAXSIZE];
int h,w,number;
int x[4]={-1,1,0,0};
int y[4]={0,0,-1,1};

void dfs(int i,int j)
{
 int d,p,q;
 for(d=0;d<4;d++)
 {
	p=i+x[d];
	q=j+y[d];
	if(p>=0&&p<h&&q>=0&&q<w&&Graph[i][j]==Graph[p][q]&&visited[p][q]==0)
	{
      visited[p][q]=1;
	  dfs(p,q);
	}
 }
}

int main()
{
	int i,j;
	memset(visited,0,sizeof(visited));
	while(cin>>h&&cin>>w&&h!=0&&w!=0)
	{
		number=0;
		for(i=0;i<h;i++)
			for(j=0;j<w;j++)
				cin>>Graph[i][j];
		for(i=0;i<h;i++)
			for(j=0;j<w;j++)
			{
				if(!visited[i][j])
				{
					visited[i][j]=1;
					dfs(i,j);
                    number++;
				}	
			}
	cout<<number<<endl;
	}
return 0;
}