#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <numeric>
#include <ctime>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <map>

using namespace std;
typedef long long int lint;

void paint(int H, int W, int** map, int x, int y, int kind)
{
	if (x < 0 || x >= W) return;
	if (y < 0 || y >= H) return;
	if (map[y][x] != kind) return;
	map[y][x] = -1;
	paint(H, W, map, x - 1, y, kind);
	paint(H, W, map, x + 1, y, kind);
	paint(H, W, map, x, y - 1, kind);
	paint(H, W, map, x, y + 1, kind);
}

int solve(int H, int W, int** map)
{
	int count = 0;
	for (int y = 0; y < H; y++){
		for (int x = 0; x < W; x++){
			if (map[y][x] == -1) continue;
			paint(H, W, map, x, y, map[y][x]);
			count++;
		}
	}
	return count;
}

int main()
{
	//clock_t start = clock();

	while (1)
	{
		int H, W;
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		int** map = new int*[H];
		for (int i = 0; i < H; i++) map[i] = new int[W];
		string buf;
		for (int i = 0; i < H; i++){
			cin >> buf;
			for (int j = 0; j < W; j++){
				if (buf[j] == '@')			map[i][j] = 1;
				else if (buf[j] == '#')		map[i][j] = 2;
				else						map[i][j] = 3;
			}
		}
		cout << solve(H, W, map) << endl;
		for (int i = 0; i < H; i++) delete[] map[i];
		delete[] map;
	}

	//clock_t end = clock();
	//std::cout << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";

	return 0;
}