#include <iostream>
#include <sstream>
#include <cstdlib>

const int MAX_W = 100;
const int MAX_H = 100;
int H, W;
char field[MAX_H][MAX_W] = {'.'};

void solve(int y, int x) {
    int dx[4] = {-1, 0, 1, 0};
    int dy[4] = {0, 1, 0, -1};
    char c = field[y][x];
    field[y][x] = '.';

    for(int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(nx >= 0 and ny >= 0 and nx < W and ny < H and field[ny][nx] == c) {
            solve(ny, nx, H, W);
        }
    }


}

void print(int w, int h) {
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            std::cout << field[i][j];
        }
        std::cout << std::endl;
    }

    std::cout << std::endl;
}

int main() {
    while (std::cin >> H >> W, H) {
        for (int i = 0; i < H; i++) {
            std::cin >> field[i];
        }

        int count = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (field[i][j] != '.') {
                    solve(i, j);
                    count++;
                }
            }
        }
        std::cout << count << std::endl;
    }

    return 0;
    return 0;
}