#include <iostream>
// #include <algorithm>

using namespace std;

void dfs(int i, int j, int row, int col, char fruit, char orchard[][100]) {
    orchard[i][j] = '.';
    if(i > 0 && orchard[i-1][j] == fruit)
        dfs(i-1, j, row, col, fruit, orchard);
    if(i < row-1 && orchard[i+1][j] == fruit)
        dfs(i+1, j, row, col, fruit, orchard);
    if(j > 0 && orchard[i][j-1] == fruit)
        dfs(i, j-1, row, col, fruit, orchard);
    if(j < col-1 && orchard[i][j+1] == fruit)
        dfs(i, j+1, row, col, fruit, orchard);
}

int main() {
    char orchard[100][100];
    while(1) {
        int col, row, num = 0;
        cin >> row >> col;
        if(col*row == 0)
            break;
        for(int i = 0; i < row; i++) {
            for(int j = 0; j < col; j++) {
                cin >> orchard[i][j];
            }
        }

        for(int i = 0; i < row; i++) {
            for(int j = 0; j < col; j++) {
                if(orchard[i][j] != '.') {
                    num++;
                    dfs(i, j, row, col, orchard[i][j], orchard);
                }
            }
        }
        cout << num << endl;
    }
    return 0;
}
