#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#define INF 0x3f3f3f3f
#define MAXSIZE 1005

using namespace std;

int n,m,vis[MAXSIZE][MAXSIZE],dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
char Map[MAXSIZE][MAXSIZE];

int check(int x,int y,char ch)
{
    if(x>=0 && x<n && y>=0 && y<m && Map[x][y]==ch && !vis[x][y])
        return 1;
    return 0;
}

void dfs(int x,int y,char ch)
{
    for(int i=0;i<4;i++)
    {
        int new_x = x + dir[i][0];
        int new_y = y + dir[i][1];
        if(check(new_x,new_y,ch))
        {
            vis[new_x][new_y] = 1;
            dfs(new_x,new_y,ch);
        }
    }
}

int main()
{
    int ans;
    while(scanf("%d%d",&n,&m),n+m)
    {
        ans=0;
        memset(Map,0,sizeof(Map));
        memset(vis,0,sizeof(vis));

        for(int i=0;i<n;i++)
        {
            scanf("%s",Map[i]);
        }

        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(vis[i][j])
                    continue;
                else
                {
                    ans++;
                    vis[i][j] = 1;
                    dfs(i,j,Map[i][j]);
                }
            }
        }

        printf("%d\n",ans);
    }
    return 0;
}