#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;

//定数
const int MAX_H = 100;
const int MAX_W = 100;
//入力
int H, W;
char field[MAX_H+10][MAX_W+10]; 

void dfs(int x, int y, char c){
    field[x][y] = '.';

    int nx, ny;
    int dx[4] = {-1, 0, 1, 0};
    int dy[4] = {0, 1, 0, -1};
    for (int i=0; i<4;i++){
        nx = x + dx[i];  ny = y + dy[i];
        if (field[nx][ny] == c) {
            dfs(nx, ny, c);
        }
    }
}

int solve(){
    int res = 0;
    char fruits[3] = {'#', '*', '@'};
    for (int i=1; i<=H; i++){
        for (int j=1; j<=W; j++){
            if (field[i][j] == fruits[0]){
                dfs(i, j, fruits[0]);
                res++;
            }else if(field[i][j] == fruits[1]){
                dfs(i, j, fruits[1]);
                res++;
            }else if(field[i][j] == fruits[2]){
                dfs(i, j, fruits[2]);
                res++;
            }
        }
    }

    return res;
}

int main(){
    queue<int> res;

    while (cin>>H && cin>>W && H!=0 && W!=0){
        for (int i=0; i<MAX_H+10; i++){
            for (int j=0; j<MAX_W+10; j++){
                field[i][j] = '.';
            }
        }


        for (int i=1; i<=H; i++){
            for (int j=1; j<=W; j++){
                cin >> field[i][j];
            }
        }
        res.push(solve());
    }

    while (res.size()){
        printf("%d\n", res.front());
        res.pop();
    }

    return 0;
}
