#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

const int maxn = 110;
const int INF = 0x3f3f3f3f;
const int mod = 1e9; 

char MAP[maxn][maxn];
bool use[maxn][maxn];
int N,M;
const int way[4][2] = {1,0,-1,0,0,1,0,-1};
bool check(int x,int y)
{
	return x >= 1 && x <= N && y >= 1 && y <= M ;
}
void dfs(int x,int y)
{
	use[x][y] = 1;
	for(int i = 0; i < 4 ; i ++)
	{
		int X = x + way[i][0];
		int Y = y + way[i][1];
		if(check(X,Y) && !use[X][Y] && MAP[X][Y] == MAP[x][y])
		{
			dfs(X,Y);
		}
	}
}
int main()
{
	while(~scanf("%d%d",&N,&M) && (N || M))
	{
		for(int i = 1; i <= N ; i ++)
		{
			for(int j = 1; j <= M ; j ++)
			{
				cin >> MAP[i][j];
			}
		}
		memset(use,0,sizeof(use));
		int sum = 0;
		for(int i = 1; i <= N ; i ++)
		{
			for(int j = 1; j <= M ; j ++)
			{
				if(!use[i][j])
				{
					dfs(i,j);
					sum++;
				}
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}
