#include<iostream>
#include<string.h>

using namespace std;

char mat[1002][1002];
int m, n;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
int ans;


int dfs(int x, int y, char ch){
    mat[x][y] = '.';

    for(int i = 0; i < 4; ++i){
        int gx = x + dx[i], gy = y + dy[i];
        if(0 <= gx && gx < m && 0 <= gy && gy < n
           && mat[gx][gy] == ch){
               dfs(gx, gy, ch);
           }
    }
    return 0;
}

void solve(){
    memset(mat, 0, sizeof(mat));
    for(int i = 0; i < m; ++i){
        for(int j = 0; j < n; ++j){
            cin>>mat[i][j];
        }
    }

    ans = 0;
    for(int i = 0; i < m; ++i){
        for(int j = 0; j < n; ++j){
            if(mat[i][j] != '.'){
                ans++;
                dfs(i, j, mat[i][j]);
            }
        }
    }
    cout<<ans<<endl;
}

int main(){
    while(cin>>m>>n && m > 0 && n > 0){
        solve();
    }
    return 0;
}

