#include <iostream>
#include <algorithm>
using namespace std;
const int N = 105;
char a[N][N];

const int dx[4] = {-1,0,1,0},dy[4] = {0,1,0,-1};
int H,W;
void dfs(int x,int y,char z)
{
	for(int i = 0;i < 4;++i)
	{
		int nx = x + dx[i],ny = y + dy[i];
		if(nx >= 0 && nx < H && ny >= 0 && ny < W && a[nx][ny] == z)
		{
			a[nx][ny] = '0';
			dfs(nx,ny,z);
		}
	}
}

int main()
{
	cin >> H >> W;
	while(H && W)
	{
		for( int i = 0;i < H;++i)	cin >> a[i];
		int res = 0;
		for(int i = 0;i < H;++i)
			for(int j = 0;j < W;++j)
				if(a[i][j] != '0')
					dfs(i,j,a[i][j]),++res,a[i][j] = '0';
		cout << res << endl;
		cin >> H >> W;		
	}
	
	return 0;
}
