#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <deque>
#include <memory.h>
using namespace std;

typedef struct _POINT
{
	int x, y;
	_POINT() {};
	_POINT(int _x, int _y) : x(_x), y(_y) {};
} POINT;

#define rep(idx, max)			for(int idx = 0, idx##Max = (max); idx < idx##Max; idx ++)
#define rrep(idx, min, max)	for(int idx = (min), idx##Max = max; idx < idx##Max; idx ++)
#define erep(idx, min, max)	for(int idx = (min), idx##Max = max; idx <= idx##Max; idx ++)

#define rev(idx, max)			for(int idx = (max) - 1; idx >= 0; idx --)
#define rrev(idx, min, max)	for(int idx = (max) - 1, idx##Min = (min); idx >= idx##Min; idx --)
#define erev(idx, min, max)	for(int idx = (max), idx##Min = (min); idx >= idx##Min; idx --)

#define foreach(it, obj)	for(auto it = obj.begin(), it##End = obj.end(); it >= it##End; it ++)

#define MAX_N	128

int g_width, g_height;	//! ??????????????????
char g_map[MAX_N][MAX_N];	//! ??????????????±
char g_mapVisited[MAX_N][MAX_N];	//! ?????????????¨?????????????

///
/// ???????????¨??? (for debugging)
///
void	PrintMap()
{
	erep(y, 1, g_height)	{	erep(x, 1, g_width)	{	::printf("%02d", g_map[y][x]);	}	::puts("");	}	::puts("");
}

///
/// ??????????????±??\???
///
void	InitMap()
{
	::memset(g_map, -1, sizeof(g_map));
	::memset(g_mapVisited, 0, sizeof(g_mapVisited));
	
	erep(y, 1, g_height)	erep(x, 1, g_width)	{	std::cin >> g_map[y][x];	}
}

///
/// ?????????????????£?¶??????????????¨?????????°?????????????????°??§???????????¶???
///
void	BfsFill(POINT start)
{
	static int dx[]	= {0, +1, 0, -1};
	static int dy[]	= {+1, 0, -1, 0};
//	static POINT dr[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
	deque<POINT>	que;
	
	int	field	= g_map[start.y][start.x];
	que.push_back(start);
	
	while(que.size())
	{
		rep(i, que.size())
		{
			POINT p = que.front();
			g_mapVisited[p.y][p.x]	= true;
			rep(n, 4)
			{
				POINT	pn(p.x + dx[n], p.y + dy[n]);
				if(g_map[pn.y][pn.x] == field && !g_mapVisited[pn.y][pn.x])
				{	que.push_back(pn);	}
			}
			que.pop_front();
		}
	}
}

///
/// ?§£???
///
int	Solve()
{
	int 	count = 0;
	erep(y, 1, g_height) erep(x, 1, g_width)
	{
		// ???????????¶?????????????????????
		if(g_mapVisited[y][x])	{	continue;	}
		// ??°?????????????????¶?????¨???????????????
		count ++;
		::BfsFill(POINT(x, y));
	}
	return(count);
}

int main()
{
	while(std::cin >> g_width >> g_height, g_width)
	{
		::InitMap();
		cout << ::Solve() << endl;
	}
}