#include <iostream>
#include<string>
using namespace std;
int H,W;
int mx[4] = {-1,0,1,0};
int my[4] = {0,-1,0,1};
int res = 0;

char lists[100][100];

void dfs(int x, int y, char c) {
    lists[y][x] = '0';
    for (int i = 0; i < 4; i++) {
        int nx = x + mx[i];
        int ny = y + my[i];
        if (lists[ny][nx] == c && 0<=nx && nx<=W+1 && 0<=ny && ny<=H+1) {
            dfs(nx, ny, c);
        }
    }
}

void solve() {
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (lists[y][x] != '0') {
                res++;
                dfs(x, y, lists[y][x]);
            }
        }
    }
}

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

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