#include <cstdio>
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
bool b[101][101];
char g[101][101];
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };
int H, W;
void dfs(int i,int j)
{
    if (b[i][j]) return;
    b[i][j] = true;
    rep(d, 4) {
        int r = i + dy[d];
        int c = j + dx[d];
        if (r < 0 || r >= H || c < 0 || c >= W || g[r][c] != g[i][j]) continue;
        dfs(r, c);
    }
}
int main()
{
    while (true) {
        scanf("%d%d", &H, &W);
        if (!(H | W)) break;
        rep(i, H) rep(j, W) b[i][j] = false;
        rep(i, H) scanf("%s", g[i]);
        int res = 0;
        rep(i, H) rep(j, W) if (!b[i][j]) {
            res++;
            dfs(i, j);
        }
        printf("%d\n", res);
    }
    return 0;
}