#include <bits/stdc++.h>
//using namespace std;
int next[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
char mp[100][105];
int book[105][105];
int n,m;
bool fun(int x,int y)
{
    return x >= 0 && y >= 0 && x < n && y < m;
}
void dfs(int x,int y)
{
    book[x][y] = 1;
    for(int k = 0; k <= 3; k++)
    {
        int dx = x + next[k][0], dy = y + next[k][1];
        if(!fun(dx,dy) || mp[dx][dy] != mp[x][y] || book[dx][dy] == 1) continue;
        dfs(dx,dy);
    }
}
int main()
{
    while(scanf("%d %d",&n,&m) == 2 && n && m)
    {
        int cnt = 0;
        memset(book,0,sizeof(book));
        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(book[i][j] == 0)
            {
                dfs(i,j);
                cnt++;
            }
        printf("%d\n",cnt);

    }


    return 0;
}

