#include <iostream>
#include <cstdio>

using namespace std;

#define H_MAX 100
#define W_MAX 100

int H, W;

char map[H_MAX][W_MAX];

void get_input() {
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            map[i][j] = getchar();
        }
        getchar();
    }
}

int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

void dfs(int h, int w) {
    if (h < 0 || H <= h || w < 0 || W <= w) return;
    char k = map[h][w];
    map[h][w] = 'X';
    for (int i = 0; i < 4; i++) {
        int nx = w + dx[i], ny = h + dy[i];
        if (map[ny][nx] == k) dfs(ny, nx);
    }
}

//void debug(int count) {
//    cout << "count: " << count << endl;
//    for (int i = 0; i < H; i++) {
//        for (int j = 0; j < W; j++) {
//            cout << map[i][j];
//        }
//        cout << endl;
//    }
//}

int solve() {
    int count = 0;
//    debug(0);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (map[i][j] != 'X') {
                count++;
                dfs(i, j);
//                debug(count);
            }
        }
    }
    return count;
}

int main() {
    while (cin >> H >> W, (H || W)) {
        getchar(); // 最初の改行をつぶす
        get_input();
        cout << solve() << endl;
    }
    return 0;
}