#include <cstdio>
#include <math.h>
#include <algorithm>

#define MAX_W 100
#define MAX_H 100

int W,H;

char field[MAX_W][MAX_H];

int dx[4] = { 1,0,-1,0};
int dy[4] = { 0,1,0,-1};

int ans_1 = 0;
int ans_2 = 0;
int ans_3 = 0;

void
solve_aoj0118();

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

    solve_aoj0118();

    return 0;
}

void
dfs(int x,int y,char magic)
{
    field[x][y] = '.';
    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 &&
            field[nx][ny] !='.' &&
            field[nx][ny] == magic)
        {
            dfs(nx,ny,magic);
        }
    }
    return;
}

void
solve_aoj0118()
{
    for (int i = 0; i < W; i++)
    {
        for (int j = 0; j < H; j++)
        {
            if (field[i][j] == '*')
            {
                dfs(i,j,'*');
                ans_1++;
            }
            else if (field[i][j] == '#')
            {
                dfs(i,j,'#');
                ans_2++;
            }
            else if (field[i][j] == '@')
            {
                dfs(i,j,'@');
                ans_3++;
            }
        }
    }

    printf("%d",ans_1+ans_2+ans_3);
}