#include <iostream>

using namespace std;

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

void paint(int sx, int sy, char k, int w, int h, string field[])
{
    field[sy][sx] = '.';

    for (int i = 0; i < 4; i++) {
        int nx = sx + dx[i];
        int ny = sy + dy[i];
        if ((nx >= 0) && (nx < w) && (ny >= 0) && (ny < h)) {
            if (field[ny][nx] == k) {
                paint(nx, ny, k, w, h, field);
            }
        }
    }
}

int count_div(int w, int h, string field[])
{
    int num = 0;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if ((field[i][j] == '#') || (field[i][j] == '*') || (field[i][j] == '@')) {
                char kind = field[i][j];
                num++;
                paint(j, i, kind, w, h, field);
            }
        }
    }
    return num;
}

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

    for (;;) {
        int num = 0;
        cin >> w >> h;
        if ((w == 0) && (h == 0)) {
            break;
        }
        for (int i = 0; i < h; i++) {
            cin >> field[i];
        }

        cout << count_div(w, h, field) << endl;
    }
    return 0;
}