#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
using ll = long long;
const int maxn = 104;
const int INF = 0x3f3f3f3f;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

int m, n; char s[maxn][maxn];

void dfs(int x, int y, char c) {
    if(x < 0 || y < 0 || x >= m || y >= n)
        return;
    if(s[x][y] != c)
        return;
    s[x][y] = '0';
    for(int i = 0; i < 4; ++i) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        dfs(nx, ny, c);
    }
}

int main() {
    while(~scanf("%d%d", &m, &n) && (n || m)) {
        for(int i = 0; i < m; ++i) {
            getchar();
            for(int j = 0; j < n; ++j) {
                s[i][j] = getchar();
            }
        }
        int ans = 0;
        for(int i = 0; i < m; ++i) {
            for(int j = 0; j < n; ++j) {
                if(s[i][j] != '0') {
                    dfs(i, j, s[i][j]);
                    ++ans;
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

