#include<algorithm>
#include<iostream>
#include<string.h>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
using namespace std;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
const double PI=acos(-1.0);
const int maxn=100010;
typedef __int64 ll;
char maze[150][150];
int n,m;
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
void dfs(int x,int y)
{
    int i,nx,ny;
    char t=maze[x][y];
    maze[x][y]=0;
    for(i=0;i<4;i++)
    {
        nx=x+dx[i];
        ny=y+dy[i];
        if(nx>=0&&nx<n&&ny>=0&&ny<m&&maze[nx][ny]==t)
            dfs(nx,ny);
    }
}
int main()
{
    int i,j,ans;

    while(scanf("%d%d",&n,&m),n||m)
    {
        ans=0;
        for(i=0;i<n;i++)
            scanf("%s",maze[i]);
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                if(maze[i][j]!=0)
                {
                    ans++;
                    dfs(i,j);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}