//
// Created by 芹川武尊 on 2019/09/04.
//

#include <iostream>
#include <vector>

typedef long long ll;

using namespace std;

unsigned int H, W;

void dfs(int i, int j, vector<vector<char> >& m) {
    char tmp = m[i][j];
    m[i][j] = '.';
    if (j + 1 < W) {
        if (tmp == m[i][j+1]) dfs(i, j+1, m);
    }
    if (i + 1 < H) {
        if (tmp == m[i+1][j]) dfs(i+1, j, m);
    }
    if (j - 1 >= 0) {
        if (tmp == m[i][j-1]) dfs(i, j-1, m);
    }
    if (i - 1 >= 0) {
        if (tmp == m[i-1][j]) dfs(i-1, j, m);
    }
}

int solve() {
    vector<vector<char> > m(H, vector<char>(W, ' '));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> m[i][j];
        }
    }

    int tmp;
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (m[i][j] != '.') {
                ans++;
                dfs(i, j, m);
            }
        }
    }
    cout << ans << endl;
}

int main() {
    while(true) {
        cin >> H >> W;
        if (H == 0) break;
        solve();
    }
    return 0;
}
