#include <iostream>
using namespace std;


#define MaxH 20
#define MaxW 20
int W,H;
bool visited[MaxH][MaxW];
char A[MaxH][MaxW];
int dx[4] = {-1,0,1,0},dy[4] = {0,1,0,-1};

void dfs(int x, int y){
    for (int i = 0; i < 4; ++i) {
        int nextx = x + dx[i];
        int nexty = y + dy[i];

        if (nextx >=0 && nextx < H && nexty < W && nexty >= 0){
            if (!visited[nextx][nexty]){
                if ( A[x][y] == A[nextx][nexty]){
                    visited[nextx][nexty] = true;
                    dfs(nextx, nexty);
                }else
                    continue;
            }

        }
    }
}
int main(){
    cin>>W>>H;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin>>A[i][j];
        }
    }
    int res = 0;

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (!visited[i][j]){
                dfs(i,j);
                res++;
            }
        }
    }
    cout<<res;
    return 0;
}
