#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<iterator>
#include<queue>
#include<ctime>
#include<bitset>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
//#define ll __int64
#define ll long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
char mp[105][105];
int vis[105][105];
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
int n,m;
bool isok(int x,int y)
{
    return x>=0&&x<n&&y>=0&&y<m;
}
void dfs(int x,int y,char e)
{
    vis[x][y]=1;
    for(int d=0;d<4;d++)
    {
        int nx=x+dx[d];
        int ny=y+dy[d];
        if(isok(nx,ny)&&!vis[nx][ny]&&mp[nx][ny]==e)
        {
            dfs(nx,ny,e);
        }
    }
}
int main()
{
    while(scanf("%d%d",&n,&m))
    {
        if(n+m==0) break;
        memset(vis,0,sizeof(vis));
        int ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s",&mp[i]);
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(!vis[i][j])
                {
                    ans++;
                    dfs(i,j,mp[i][j]);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}