#include <iostream>

using namespace std;

char mat[102][102];
int direct[5] = {-1, 0, 1, 0, -1};
int m, n;
int ans;


void dfs(int x, int y) {
    if (mat[x][y] == '.') return;
    char t = mat[x][y];
    mat[x][y] = '.';
    for (int i = 0; i < 4; ++i) {
        int xx = x + direct[i];
        int yy = y + direct[i + 1];
        if (0 <= xx and xx < m and 0 <= yy and yy < n and mat[xx][yy] == t) {
            dfs(xx, yy);
        }
    }
}

void solve() {
    ans = 0;
    for (int i = 0; i < m; ++i) {
        cin >> mat[i];
    }
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            if (mat[i][j] != '.') {
                ++ans;
                dfs(i, j);
            }
        }
    }
}

int main() {
    while (cin >> m >> n and n > 0 and m > 0) {
        solve();
        cout << ans << endl;
    }
}
