#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int visited[100][100],s1,s2;
char m[100][100];
void dfs(int x,int y,char c)
{
 //   cout<<x<<y<<endl;
    visited[x][y]=1;
    if(x-1>=0&&m[x-1][y]==c&&visited[x-1][y]==0)
    {
        dfs(x-1,y,c);
    }
    if(y-1>=0&&m[x][y-1]==c&&visited[x][y-1]==0)
    {
        dfs(x,y-1,c);
    }
    if(x+1<s1&&m[x+1][y]==c&&visited[x+1][y]==0)
    {
        dfs(x+1,y,c);
    }
    if(y+1<s2&&m[x][y+1]==c&&visited[x][y+1]==0)
    {
        dfs(x,y+1,c);
    }
}
int main()
{
    while(scanf("%d%d",&s1,&s2)!=EOF)
    {
        memset(visited,0,sizeof(visited));
        int ans=0;
        getchar();
        if(s1==0&&s2==0)
            break;
        for(int i=0;i<s1;i++)
        {
            for(int j=0;j<s2;j++)
            {
                scanf("%c",&m[i][j]);
            }
            getchar();
        }
        for(int i=0;i<s1;i++)
        {
            for(int j=0;j<s2;j++)
            {
                if(visited[i][j]==0)
                {
               //     cout<<'!'<<endl;
                    ans++;
                    dfs(i,j,m[i][j]);
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

