#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
const int maxn = 100 + 5;
char tree[maxn][maxn];
int n, m;
char node;
int ans;

using namespace std;

bool dfs(int a, int b)
{
    if(tree[a][b] == 0 || tree[a][b] != node)   //螯よ棡蟾イ隶ソ髣ョ霑??閠?崟譯井ク堺ク??荳コ蛛?        return 0;
    tree[a][b] = 0;   //蟆?ョソ髣ョ霑?噪轤ケ驛ス譬?ョー荳コ0
    dfs(a - 1, b);    //蝗幄＃騾夲シ梧頗邏「蝗帑クェ譁ケ蜷?    dfs(a, b - 1);
    dfs(a + 1, b);
    dfs(a, b + 1);
    return 1;
}


int main()
{
    while(scanf("%d%d", &n, &m) != EOF){
        ans = 0;
        if(n == 0 && m == 0)
            break;
        for(int i = 0; i < n; i++){
            scanf("%s", tree[i]);
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                    node = tree[i][j];
                    if(dfs(i, j))
                    ans++;
                }
            }
        printf("%d\n", ans);
    }
    return 0;
}