#include <iostream>
#include <cstring>

using namespace std;
const int maxn = int(100) + 5;

const int d[4][2] = {{0, 1}, {0, -1}, {1, 0 }, {-1, 0}};
//                     {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
char G[maxn][maxn];
int n, m;
int visited[maxn][maxn];

bool check(int x, int y, char c) {
    return x < n and x >= 0 and y < m and y >= 0
            and G[x][y] == c and not visited[x][y];
}

void dfs(int x, int y, char c) {
    for (int i = 0; i < 4; i++) {
        int dx = x + d[i][0];
        int dy = y + d[i][1];
        if (check(dx, dy, c)) {
            visited[dx][dy] = true;
            dfs(dx, dy, c);
        }
    }
}


int main() {
    while (cin >> n >> m and (n or m)) {
        memset(visited, false, sizeof(visited));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cin >> G[i][j];
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (not visited[i][j]) {
                    ans ++;
                    visited[i][j] = true;
                    dfs(i, j, G[i][j]);
                }
            }
        }
        cout << ans << endl;
    }
}

