#define within(x, _l, _r) ((x >= _l) && (x <= _r))
#include <iostream>
using namespace std;

const int MAXN = 1e2;
char mat[MAXN][MAXN];
int n, m, res;

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

void dfs(int cx, int cy){
    char save = mat[cx][cy];
    mat[cx][cy] = '!';
    for (int i = 0; i < 4; ++ i){
        int nx = cx + dx[i], ny = cy + dy[i];
        if (within(nx, 0, n - 1) && within(ny, 0, m - 1) && mat[nx][ny] == save) dfs(nx, ny);
    }
}

int main(){
    while (cin >> n >> m){
        if (n == 0 && m == 0) break;
        res = 0;
        for (int i = 0; i < n; ++ i){
            for (int j = 0; j < m; ++ j){
                cin >> mat[i][j];
            }
        }

        for (int i = 0; i < n; ++ i){
            for (int j = 0; j < m; ++ j){
                if (mat[i][j] == '!') continue;
                dfs(i, j);
                ++ res;
            }   
        }

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