#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

vector <string> M;
int w, h;

void search( int x, int y, char c )
{
	M[y][x] = '.';
	for ( int i = -1; i < 2; i++ )
	{
		for ( int j = -1; j < 2; j++ )
		{
			if ( i != j && ( i == 0 || j == 0 ) )
			{
				int nx = x+i;
				int ny = y+j;
				if ( nx < 0 || nx >= w || ny < 0 || ny >= h )
					continue;
				if ( c == M[ny][nx] )
					search( nx, ny, c );
			}
		}
	}
}

int main( void )
{
	while ( cin >> h >> w && h != 0 && w != 0 )
	{
		M = vector <string>( h );
		for ( int i = 0; i < h; i++ )
			cin >> M[i];

		int kotae = 0;
		for ( int i = 0; i < h; i++ )
		{
			for ( int j = 0; j < w; j++ )
			{
				if ( M[i][j] != '.' )
				{
					kotae++;
					search( j, i, M[i][j] );
				}
			}
		}
		cout << kotae << endl;
	}

	return 0;
}