#include<iostream>
#include<cstdio>
using namespace std;
#define N 10
int h, w;
char map[N][N+1];
int cnt;

void dfs(int x, int y, char c)
{
	map[x][y] = 'X';
	int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
	for (int i = 0; i < 4; i ++) 
	{  
        int nx = x + d[i][0], ny = y + d[i][1];  
        if (0 <= nx && nx < h && 0 <= ny && ny < w && map[nx][ny] == c) 
            dfs(nx, ny, c);
    }
}

void solve()
{
	cnt = 0;
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			if(map[i][j] != 'X')
			{
				dfs(i, j, map[i][j]);
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}

int main()
{
	while(cin >> h >> w, h || w)
	{
		for(int i = 0; i < h; i++)
			cin >> map[i];
		solve();
	}
	return 0; 
}