#include <bits/stdc++.h>
using namespace std;

int h, w;
char board[101][101];
int d[101][101];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

void dfs(int x, int y) {
    d[x][y] = 1;
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx >= 0 && nx < h && ny >= 0 && ny < w && d[nx][ny] == 0 &&
            board[nx][ny] == board[x][y]) {
            dfs(nx, ny);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    while (cin >> h >> w && !(h == 0 && w == 0)) {
        memset(d, 0, sizeof(d));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) cin >> board[i][j];
        }
        int r = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (d[i][j] == 0) {
                    r++;
                    dfs(i, j);
                }
            }
        }
        cout << r << "\n";
    }
}
