#include <iostream>

using namespace std;

void replace(string *field, char c, int sx, int sy, int w, int h)
{
    static const int dx[] = {-1,  0, 0, 1};
    static const int dy[] = { 0, -1, 1, 0};

    field[sy][sx] = '.';
    for (int i = 0; i < 4; i++) {
        if (((sx + dx[i] >= 0) && (sx + dx[i] < w)) &&
                ((sy + dy[i] >= 0) && (sy + dy[i] < h))) {
            if (field[sy + dy[i]][sx + dx[i]] == c) {
                replace(field, c, sx + dx[i], sy + dy[i], w, h);
            }
        }
    }
}


int main(int argc, char **argv)
{
    int w, h;
    string field[100];

    cin >> w >> h;
    while ((w != 0) && (h != 0)) {
        int num = 0;

        for (int i = 0; i < h; i++) {
            cin >> field[i];
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (field[i][j] != '.') {
                    num++;
                    replace(field, field[i][j], j, i, w, h);
                }
            }
        }
        cout << num << endl;
        cin >> w >> h;
    }

    return 0;
}
 