#include<cstdio>
#include<cstring>

const int MAX_N = 102;
const int MAX_M = 102;
int n, m;
char field[MAX_N][MAX_M];
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
bool vis[MAX_N][MAX_M];

void dfs(int x, int y, int flag) {
    vis[x][y] = 1;
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
            if (flag == 1) {
                if (field[nx][ny]== '#'&&!vis[nx][ny])
                    dfs(nx, ny, flag);
            } else if (flag == 2) {
                if (field[nx][ny] == '@' && !vis[nx][ny])
                    dfs(nx, ny, flag);
            } else {
                if (field[nx][ny] == '*' && !vis[nx][ny])
                    dfs(nx, ny, flag);
            }
        }
    }
    return;
}

void solve() {
    int ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (field[i][j] == '#' && !vis[i][j]) {
                ans++;
                dfs(i, j, 1);
            } else if (field[i][j] == '@' && !vis[i][j]) {
                ans++;
                dfs(i, j, 2);
            } else {
                if (!vis[i][j]) {
                    ans++;
                    dfs(i, j, 3);
                }
            }
        }
    printf("%d\n", ans);
}

int main() {
    while (scanf("%d%d", &n, &m) != EOF) {
        if (n == 0 && m == 0)break;
        memset(vis, 0, sizeof (vis));
        for (int i = 0; i < n; i++)
            scanf("%s", field[i]);
        solve();
    }
    return 0;
}