#include <cstdio>
#include <cstring>
 
const int MAX_H = 100;
const int MAX_W = 100;
 
//&#36755;入
int H, W;
char g[MAX_H][MAX_W + 1];
 
bool f[MAX_H][MAX_W];                   //&#26631;&#35760;&#35813;位置是否已到&#36798;
 
int d[4][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};       //方向
 
//深度&#20248;先遍&#21382;g[i][j]同&#31867;局域
void dfs(int x, int y, int c){
    if(f[x][y]) return;
    f[x][y] = true;
    for(int i = 0; i < 4; i ++){
        int nx = x + d[i][0], ny = y + d[i][1];
        if(0 <= nx && nx < H && 0 <= ny && ny < W && g[nx][ny] == c && !f[nx][ny]){
            dfs(nx, ny, c);
        }
    }
}
 
void solve(){
    //初始化
    memset(f, 0, sizeof(bool) * H * W);
    //遍&#21382;果&#22253;，&#27599;到一个新位置，遍&#21382;&#35813;位置能到&#36798;的地方
    int ans = 0;
    for(int i = 0; i < H; i ++){
        for(int j = 0; j < W; j ++){
            if(!f[i][j]){
                ans ++;
                dfs(i, j, g[i][j]);
            }
        }
    }
    printf("%d\n", ans);
}
 
int main(int argc, char const *argv[]){
 
    while(scanf("%d %d", &H, &W)){
        if(H == 0 && W == 0) break;
        for(int i = 0; i < H; i ++){
            scanf("%s", g[i]);
        }
        solve();
    }
 
    return 0;
}