#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

typedef long long ll;

using namespace std;

int H, W;
char orchard[128][128];
void destroy_orchard(char f, int x, int y)
{
	if (x < 0 || y < 0 || x >= W || y >= H || orchard[y][x] != f)
		return;

	orchard[y][x] = 'w';
	int dx[] = { 0, 1, 0, -1 };
	int dy[] = { 1, 0, -1, 0 };
	for (int i = 0; i < 4; ++i)
		destroy_orchard(f, x + dx[i], y + dy[i]);
}
int main()
{
	while (true)
	{
		char buf[128];
		cin.getline(buf, sizeof(buf));
		sscanf(buf, "%d %d", &H, &W);
		if (H == 0 && W == 0)
			break;

		for (int i = 0; i < H; ++i)
			cin.getline(orchard[i], sizeof(orchard[i]));

		int ans = 0;
		for (int i = 0; i < H; ++i)
		{
			for (int j = 0; j < W; ++j)
			{
				if (orchard[i][j] != 'w')
				{
					++ans;
					destroy_orchard(orchard[i][j], j, i);
				}
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}