#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
const int Max = 100 + 5;
int n, m;
char g[Max][Max];
int ans = 0;
int dx[5] = {0, 1, 0, -1, 0};
int dy[5] = {0, 0, 1, 0, -1};
void dfs(int x, int y, char ch) {
    g[x][y] = '0';
    for (int i = 1; i <= 4; i++) {
        int xx = x + dx[i], yy = y + dy[i];
        if(xx >= 1 && xx <= n && yy >= 1 && yy <= m && g[xx][yy] == ch)
            dfs(xx, yy, ch);
    }
}
int main() {
    while(scanf("%d %d", &n, &m) == 2 && n && m) {
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                cin >> g[i][j];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if(g[i][j] != '0') {
                    dfs(i, j, g[i][j]);
                    ans++;
                }
            }
        }
        printf("%d\n", ans);
        ans = 0;
    }
    return 0;
}
