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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )
#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = (c).begin(); it != (c).end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define PB( n ) push_back( ( n ) )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define fst first
#define snd second

bool inside( vector<string> &field, int i, int j )
{
	return 0 <= i && i < field.size() && 0 <= j && j < field[i].length();
}

int bfs( vector<string> &field, int i, int j, char c )
{
	if ( field[i][j] != c )
	{
		return 0;
	}

	field[i][j] = ' ';

	const int direction[][2] = {
		0, 1,
		1, 0,
		0, -1,
		-1, 0
	};

	REP( d, 0, 4 )
	{
		int ti = i + direction[d][0];
		int tj = j + direction[d][1];

		if ( inside( field, ti, tj ) )
		{
			bfs( field, ti, tj, c );
		}
	}

	return 1;
}

int main()
{
	while ( true )
	{
		int h, w;
		cin >> h >> w;

		if ( h == 0 && w == 0 )
		{
			break;
		}

		vector<string> field;

		REP( i, 0, h )
		{
			string buffer;
			cin >> buffer;
			field.PB( buffer );
		}

		int res = 0;

		REP( i, 0, field.size() )
		{
			REP( j, 0, field[i].length() )
			{
				if ( field[i][j] != ' ' )
				{
					res += bfs( field, i, j, field[i][j] );
				}
			}
		}

		cout << res << endl;
	}
	
	return 0;
}