#include<iostream>
#include<cstdio>
using namespace std;

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

bool dfs(int ss,int ts, char p){
    if(p=='.'){
        return false;
    }
    s[ss][ts] = '.';
    for(int i=0;i<4;i++){
        int xx = ss+dx[i];
        int yy = ts+dy[i];
        if(xx>=0&&xx<n&&yy>=0&&yy<m&&s[xx][yy]==p){
            dfs(xx,yy,p);
        }
    }
    return true;
}
int main(){
    while(~scanf("%d%d",&n,&m)){
        if(!n&&!m)break;
        for(int i=0;i<n;i++){
            scanf("%s",s[i]);
        }
        ans=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(dfs(i,j,s[i][j])){
                    ans++;
                }
            }
        }
        printf("%d\n",ans);
        }
    return 0;
}
