#include<stdio.h>
#include<iostream>
#include<string.h>

int H,W;
char map[100][100];
void flood(int typ, int x,int y){
    map[y][x]='X';
    printf("rewritten: map[%d][%d]:%c\n",y,x,map[y][x]);
    //up
    if(y-1>=0&&map[y-1][x]==typ)flood(typ,x,y-1);
    //right
    if(x+1<W&&map[y][x+1]==typ)flood(typ,x+1,y);
    //down
    if(y+1<H&&map[y+1][x]==typ)flood(typ,x,y+1);
    //left
    if(x-1>=0&&map[y][x-1]==typ)flood(typ,x-1,y);
}
int main(){
    while(scanf("%d%d",&H,&W)!=EOF){if(H==0&&W==0)return 0;
        for(int i=0;i<H;i++)scanf("%s",&map[i]);
        int count=0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(map[i][j]!='X'){flood(map[i][j],j,i);count++;}
            }
        }printf("%d\n",count);
    }return 0;
}