
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

int n,m;
char sq[105][105];
int sx,sy;
int answer;

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

int visited[25][25];

void dfs(int x,int y,char c){
    for(int i=0;i<4;i++){
        int nx = x+dx[i], ny = y+dy[i];
        if(1<=nx&&nx<=n&&1<=ny&&ny<=m&&sq[nx][ny]==c){
            sq[nx][ny]='.';
            dfs(nx,ny,c);
        }
    }
}

void solve(){
    while(1){
        scanf("%d%d",&n,&m);
        if(m==0&&n==0) break;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cin >> sq[i][j];
            }
        }
        answer=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(sq[i][j]!='.'){
                    answer++;
                    dfs(i,j,sq[i][j]);
                }
            }
        }
        printf("%d\n",answer);
    }
}


int main(){
    solve();
    return 0;
}

