#include <cstdio>

int H, W;
char map[100][100];
int count = 0;

void solve();
void dfs(int h, int w);


int main() {
    scanf("%d %d", &H, &W);
    while (! (H == 0 && W == 0)) {
        for (int i = 0; i != H; i ++)
            scanf("%s\n", map[i]);
        solve();
        scanf("%d %d", &H, &W);
    }
}

void solve() {
    count = 0;
    for (int i = 0; i != H; i ++)
        for (int j = 0; j != W; j ++){
            if (map[i][j] != '_') {
                /* debug
                printf("%d  %d\n", i, j);
                for (int h = 0; h != H; h ++){
                    for (int w = 0; w != W; w ++)
                        printf("%c", map[h][w]);
                    printf("\n");
                }
                */
                count ++;
                dfs(i, j);
            }
        }
    printf("%d\n", count);
}

void dfs(int h, int w) {
    char t = map[h][w];
    map[h][w] = '_';
    for (int dh = -1; dh <= 1; dh ++)
        for (int dw = -1; dw <= 1; dw ++) {
            if (dh == 0 && dw == 0) continue;
            if (0 <= h + dh
                    && h + dh < H
                    && 0 <= w + dw
                    && w + dw < W
                    && dh * dw == 0
                    && t == map[h + dh][w + dw])
                dfs(h + dh, w + dw);
        }
}