#include <iostream>
using namespace std;

int ans = 0;
int itr = 0;
char m[100][100] = { 0 };
bool sirusi[100][100] = { 0 };

void kukaku(int h, int w, int y, int x, char c, int cnt)
{
	if (y < 0 || y >= h || x < 0 || x >= w || sirusi[y][x]) {
		return;
	}

	if (m[y][x] != c) {
		return;
	}

	if (cnt == 0) {
		++ans;
	}

	sirusi[y][x] = true;

	kukaku(h, w, y + 1, x, c, cnt + 1);
	kukaku(h, w, y - 1, x, c, cnt + 1);
	kukaku(h, w, y, x + 1, c, cnt + 1);
	kukaku(h, w, y, x - 1, c, cnt + 1);
}

int main(void)
{
	int h, w;
	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0) {
			break;
		}
		ans = 0;
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				cin >> m[i][j];
			}
		}

		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				kukaku(h, w, i, j, m[i][j], 0);
			}
		}

		cout << ans << endl;
	}

	return 0;
}
