#include <iostream>
#include <queue>
#include <memory.h>

using namespace std;

const int LIM = 120;
char m[LIM][LIM];
bool vis[LIM][LIM];
int R, C;

struct node {
    int r, c;
} DIR[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

void bfs(const int & r, const int & c, char ch) {
    queue<node> q;
    node crt = {r, c};
    vis[r][c] = true;
    q.push(crt);
    while (!q.empty()) {
        crt = q.front();
        q.pop();

        m[crt.r][crt.c] = '!';

        node next;
        for (int i = 0; i < 4; i++) {
            next.r = crt.r + DIR[i].r;
            next.c = crt.c + DIR[i].c;
            if (!vis[next.r][next.c] && m[next.r][next.c] == ch && next.r >= 0 && next.r < R && next.c >= 0 && next.c < C) {
                vis[next.r][next.c] = true;
                q.push(next);
            }
        }
    }
}

int main(void) {
    while (~scanf("%d%d", &R, &C) && R && C) {
        int cnt = 0;
        getchar();
        memset(vis, false, sizeof vis);
        for (int i = 0; i < R; i++)
            fgets(m[i], LIM, stdin);

        for (int i = 0; i < R; i++)
            for (int j = 0; j < C; j++)
                if (m[i][j] != '!') {
                    cnt++;
                    bfs(i, j, m[i][j]);
                }
        printf("%d\n", cnt);
    }
    return 0;
}
