#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
int m, n, s;
char c;
char g[101][101];
int id[8] = {0, -1, 0, 1, -1, 0, 1, 0};
int main() {
    while ((~scanf("%d %d", &m, &n)) && m && n) {
        for (int i = 0; i < n; ++i) {
            getchar();
            for (int j = 0; j < m; ++j)
                while (scanf("%c", &g[i][j])==1 && g[i][j] == ' ');
        }//puts("123");
        int ans = 0;
        for (int x = 0; x < m * n; ++x) {
            if (g[s / m][s % m] != '.') {
                c = g[s / m][s % m];
                queue<int> q;
                q.push(s);
                while (!q.empty()) {
                    int i = q.front() / m, j = q.front() % m;
                    q.pop();
                    for (int k = 0; k < 8; k += 2) {
                        int ni = i + id[k], nj = j + id[k + 1];
                        if (ni >= 0 && ni < n && nj >= 0 && nj < m && g[ni][nj] == c) {
                            g[ni][nj] = '.';
                            ++ans;
                            q.push(ni * m + nj);
                        }
                    }
                }
                ++ans;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

