# include<cstdio>
# include<iostream>

using namespace std;

# define MAX 123

char grid[MAX][MAX];
int w,h;
int nxt[4][2] = { { -1, 0 },
    { 1, 0 },
    { 0, -1 },
    { 0, 1 },
    };


int can_move( int x,int y,char tree)
{
    if ( x>=0&&x<w&&y>=0&&y<h&&grid[x][y]==tree )
        return 1;
    return 0;
}


void dfs ( int x,int y,char tree )
{
    grid[x][y] = 'X';
    for ( int i = 0;i < 4;i++ )
    {
        int tx = x+nxt[i][0], ty = y+nxt[i][1];
        if ( can_move(tx,ty,tree) )
        {
            dfs( tx,ty,tree );
        }
    }
   // return;
}

int main(void)
{
    while ( scanf("%d%d",&h,&w)==2 )
    {
        if ( w==0&&h==0 )
            break;
        for ( int j = 0;j < h;j++ )
        {
           scanf("%s",grid[j]);
        }
        int cnt = 0;
        for ( int j = 0;j < h;j++ )
        {
            for ( int i = 0;i < w;i++ )
            {
                if ( grid[i][j]!='X' )
                {
                    dfs(i,j,grid[i][j]);
                    cnt++;
                }
            }
        }
        printf("%d\n",cnt);
    }


    return 0;
}