#include <iostream>
using namespace std;

const int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 };

int cnt = 0;
int n, m;
char tab[101][101];
bool memo[101][101];

void dfs(char a, int x, int y){
	for (int i = 0; i < 4; i++){
		int nx = x + dx[i], ny = y + dy[i];
		if (nx >= 0 && nx < m&&ny >= 0 && ny < n&&memo[ny][nx] == false && tab[ny][nx] == a){
			memo[ny][nx] = true;
			dfs(a, nx, ny);
		}
	}
}

int main(){
	while (1){
		cin >> m >> n;
		if (n == 0 && m == 0) break;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
				cin >> tab[i][j];
			}
		}
		for (int i = 0; i < 101; i++){
			for (int j = 0; j < 101; j++){
				memo[i][j] = false;
			}
		}

		for (int i = 0; i < m; i++){
			for (int j = 0; j < n; j++){
				if (memo[i][j] == false){
					dfs(tab[i][j], j, i);
					cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}