#include <cstdio>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <map> 
#include <iostream>
#include <cctype>
#include <utility> // 包含pair 
using namespace std;
typedef long long LL;
const int MAXN = 100 + 10;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int n, m, ans;
char maze[MAXN][MAXN];
void dfs(int x, int y, char ch) {
	maze[x][y] = '.';
	for (int i = 0; i < 4; i++) {
		int ux = x + dx[i], uy = y + dy[i];
		if (ux >= 0 && ux < n && uy >= 0 && uy < m && maze[ux][uy] == ch) {
			dfs(ux, uy, ch);
		}
	} 
}

int main() {
	// ios::sync_with_stdio(false);
	while (scanf("%d %d", &n, &m) == 2 && n && m) {
		ans = 0;
		for (int i = 0; i < n; i++) scanf("%s", &maze[i]);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				char u = maze[i][j];
				if (u != '.') {
					dfs(i, j, u);
					ans++;
				}
			}
		}
		printf("%d\n", ans);
	}
	
    return 0;
}
