#include<iostream>
#include<stack>

#define MAX_H 100
#define MAX_W 100

using namespace std;
typedef pair<int,int> P;

int h,w,res;
stack<P> fields;
P now;
char field[MAX_H][MAX_W+1];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};//EAºA¶AãÌÔ

void dfs(int x,int y,char fruit){

    fields.push(P(x,y));
    field[x][y]='%';

    while(!fields.empty()){
        now=fields.top();
        fields.pop();
        x=now.first; y=now.second;
//      cout<<x<<','<<y<<endl;
        for(int i=0;i<4;i++){
            int nx=x+dx[i]; int ny=y+dy[i];
            if(0<=nx&&nx<h&&0<=ny&&ny<w&&field[nx][ny]!='%'&&fruit==field[nx][ny]){
                fields.push(P(nx,ny));
                field[nx][ny]='%';
//              cout<<"[nx,ny="<<nx<<ny<<"]"<<endl;
            }
        }
    }

    return;
}

int main(){

    while(1){
        cin>>h>>w;
        if(w==0) break;

        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>field[i][j];
            }
        }

        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(field[i][j]!='%'){
                    dfs(i,j,field[i][j]);
                    res++;
//                  cout<<"res="<<res<<endl;
                }
            }
        }
        cout<<res<<endl;
    }

    return 0;
}