#include <iostream>
#include <cstdlib>
using namespace std;

char field[100][100];
char field2[100][100];
int h, w;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
char f[4] = {'@', '#', '*'};

void dfs(int x, int y){
    field2[x][y] = '.';
    for (int i = 0; i < 4; ++i) {
        int nx = x + dx[i], ny = y + dy[i];
        if(0<=nx && nx<h && 0<=ny && ny<w && field2[nx][ny] == 'W') dfs(nx, ny);
    }
}

int main() {
    while(1){
        cin >> h >> w;
        if(w == 0 && h == 0) break;
        int res = 0;
        for(int i = 0; i < h; ++i) {
            scanf("%s", &field[i]);
        }

        for(int k = 0; k < 3; ++k){
            for(int i = 0; i < h; ++i) {
                for(int j = 0; j < w; ++j){
                    if (field[i][j] == f[k]) {
                        field2[i][j] = 'W';
                    } else {
                        field2[i][j] = '.';
                    }
                }
            }

            for(int i = 0; i < h; ++i) {
                for(int j = 0; j < w; ++j){
                    if(field2[i][j] == 'W') {
                        dfs(i, j);
                        res++;
                    } 
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}