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

using namespace std;

#define int_ int64_t
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define lb long double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const ll N=105;
ll n,m;
char grid[N][N];
ll ans=0;
bool vis[N][N];
ll dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

void dfs(ll x,ll y) {
    vis[x][y]=1;
    for (ll i=0;i<4;i++) {
        ll xx=x+dir[i][0];
        ll yy=y+dir[i][1];
        if (xx>0&&xx<=n&&yy>0&&yy<=n) {
            if (!vis[xx][yy]&&grid[xx][yy]==grid[x][y]) dfs(xx,yy);
        }
    }
}

int main()
{
    while (true) {
        scanf("%lld%lld",&n,&m);
        if (n==0&&m==0) break;
        for (ll i=1;i<=n;i++) {
            scanf("%s",&grid[i][1]);
        }
        memset(vis,0,sizeof(vis));
        ans=0;
        for (ll i=1;i<=n;i++) {
            for (ll j=1;j<=m;j++) {
                if (!vis[i][j]) {
                    ans++;
                    dfs(i,j);
                }
            }
        }
        printf("%lld\n",ans);
    }
}
