#include <iostream>
#include <cstdio>
#include <stack>

using namespace std;

int H,W;
char field[100][100];


void dfs(int x, int y , char type){

    char cur_type = field[x][y];

    field[x][y] = '.';

    for(int dx = -1; dx<= 1; dx++){
        for(int dy = -1; dy<= 1; dy++){
            int nx = x + dx;
            int ny = y + dy;

            if( 0<= nx
                && nx < W
                && 0<= ny
                && ny < H
                && field[nx][ny] == cur_type
                && dx * dy == 0 ){
                dfs(nx,ny,cur_type);
            }
        }
    }
    return;
}


void solve(){
    int res = 0;
    for(int i = 0; i< H; i++){
        for(int j = 0; j< W; j++){
            if(field[i][j] != '.'){

                dfs(i,j,field[i][j]);

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



int main() {

    cin >> H >> W;cin.ignore();
    string line;

    for(int i = 0; i< H; i++){
        getline(cin,line);
        for(int j = 0; j< W; j++){
            field[i][j] = line[j];
        }
    }


    solve();

    return 0;
}



/*
10 10
####*****@
@#@@@@@*#*
@##***@@@*
#****#*@**
##@*#@@*##
*@@@@*@@@#
***#@*@##*
*@@@*@@##@
*@*#*@##**
@****#@@#@
0 0
 */