#include <iostream>
using namespace std;

void rec( char c, char* map, int x, int y, int w, int h )
{
	static int diff[][ 2 ] = { { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 } };

	if( map[ y * w + x ] != c ){
		return;
	}

	map[ y * w + x ] = 0;

	for( int i = 0; i < 4; ++i ){
		rec( c, map, x + diff[ i ][ 0 ], y + diff[ i ][ 1 ], w, h );
	}

	return;
}

int main()
{
	int h, w;

	while( cin >> h >> w && !( h == 0 && w == 0 ) ){
		if( h == 0 || w == 0 ){
			cout << 0 << endl;
			continue;
		}

		int hh = h + 2;
		int ww = w + 2;
		char* map = new char[ ww * hh ]();

		for( int i = 0; i < h; ++i ){
			cin >> &map[ ( i + 1 ) * ww + 1 ];
		}

		int areaCount = 0;
		for( int i = 1; i < hh; ++i ){
			for( int j = 1; j < ww; ++j ){
				char c =  map[ i * ww + j ];
				if( c == 0 ){
					continue;
				}
				rec( c, map, j, i, ww, hh );
				++areaCount;
			}
		}

		cout << areaCount << endl;

		delete[] map;
	}

	return 0;
}