#include <cstring>
#include <iostream>
using namespace std;

int X, Y;
char mat[101][101];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void dfs(int x, int y, char c) {
    mat[x][y] = 'X';
    for (int i = 0; i < 4; ++i) {
        int xx = x + dx[i];
        int yy = y + dy[i];
        if (xx >= 0 && xx < X && yy >= 0 && yy < Y && mat[xx][yy] == c) {
           dfs(xx, yy, c);
        }
    }
}

int main() {
    while (true) {
        cin >> X >> Y;
        if (X == 0 && Y == 0) break;

        for (int i = 0; i < X; ++i) {
            for (int j = 0; j < Y; ++j) {
                cin >> mat[i][j];
            }
        }

        int res = 0;
        for (int i = 0; i < X; ++i) {
            for (int j = 0; j < Y; ++j) {
                if (mat[i][j] != 'X') {
                    dfs(i, j, mat[i][j]);
                    res += 1;
                }
            }
        }

        cout << res << endl;
    }
    return 0;
}

