#include <iostream>
using namespace std;

void searchCompartment(int x, int y, int h, int w, char** field) {
    char ch = field[y][x];
    field[y][x] = '0';
    for (int nx = x - 1; nx <= x + 1; nx += 2) {
        if (0 <= nx && nx < w && field[y][nx] == ch) {
            searchCompartment(nx, y, h, w, field);
        }
    }
    for (int ny = y - 1; ny <= y + 1; ny += 2) {
        if (0 <= ny && ny < h && field[ny][x] == ch) {
            searchCompartment(x, ny, h, w, field);
        }
    }
}

int main() {
    while (true) {
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0) {
            break;
        }
        char** field = new char* [h];
        for (int i = 0; i < h; i++) {
            field[i] = new char [w + 1];
        }
        for (int i = 0; i < h; i++) {
            cin >> field[i];
        }
        int count = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (field[i][j] != '0') {
                    searchCompartment(j, i, h, w, field);
                    count++;
                }
            }
        }
        cout << count << endl;
        for (int i = 0; i < h; i++) {
            delete[] field[i];
        }
        delete[] field;
    }
}