#include<iostream>
#include<utility>
#include<queue>

using namespace std;

typedef struct
{
	int x;
	int y;
}Point;

const Point DIRE4[4] = {
	{0, -1},
	{-1, 0},
	{0, 1},
	{1, 0}
};

char field[100][101];
int H, W;
int ans = 0;

void draw(int x, int y)
{
	char target = field[y][x];
	field[y][x] = '0';
	
	queue<Point> pointQ;
	
	Point center = {x, y};
	pointQ.push(center);
	
	while(!pointQ.empty())
	{
		Point p = pointQ.front();
		pointQ.pop();
		
		for(int i = 0;i < 4;i++)
		{
			int tx = p.x + DIRE4[i].x;
			int ty = p.y + DIRE4[i].y;
			
			if(0 <= tx && tx < W && 0 <= ty && ty < H && target == field[ty][tx])
			{
				field[ty][tx] = '0';
				
				Point set = {tx, ty};
				pointQ.push(set);
			}
		}
	}
}

int main()
{
	while(1)
	{
		ans = 0;
		
		cin >> H >> W;
		if(H == 0 && W == 0) break;
		
		for(int y = 0;y < H;y++)
		{
			cin >> field[y];
		}
		
		for(int y = 0;y < H;y++)
		{
			for(int x = 0;x < W;x++)
			{
				if(field[y][x] != '0')
				{
					draw(x, y);
					ans++;
				}
			}
		}
		
		cout << ans << endl;
	}
	return 0;
}