#include <cstdio>

int H, W;
char Garden[100][100 + 1];

const char searched = 'S';

void dfs(int y, int x) {
    int dx[4] = {1, 0, 0, -1};
    int dy[4] = {0, 1, -1, 0};

    char fruit = Garden[y][x];
    Garden[y][x] = searched;

    for (int i = 0; i < 4; ++i) {
        int nx = x + dx[i];
        int ny = y + dy[i];

        if (0 <= nx && nx < W && 0 <= ny && ny < H && Garden[ny][nx] == fruit) {
            dfs(ny, nx);
        }
    }
}

int main() {
    scanf("%d%d", &H, &W);
    for (int i = 0; i < H; ++i) {
        scanf("%s", Garden[i]);
    }

    int res = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (Garden[i][j] != 'S') {
                dfs(i, j);
                res++;
            }
        }
    }

    printf("%d\n", res);
}