#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e18+7;

signed main(){

    vector<int> d = {0, 1, 0, -1, 0};

    auto f = [d]{
        int h, w;
        cin >> h >> w;
        if(!h)
            return 0;
        vector<string> s(h);
        for(auto& x : s)
            cin >> x;
        vector<bitset<100>> bs(h);

        function<void(int, int)> g = [&](int x, int y){
            bs[x].set(y);
            for(int i = 0; i < 4; ++i){
                int ax = x + d[i], ay = y + d[i + 1];
                if(ax < 0 || ay < 0 || ax >= h || ay >= w || bs[ax][ay] || s[x][y] != s[ax][ay])
                    continue;
                g(ax, ay);
            }
        };

        int ans = 0;

        for(int i = 0; i < h; ++i)
            for(int j = 0; j < w; ++j)
                if(!bs[i][j])
                    ++ans, g(i, j);
        cout << ans << endl;
        return 1;
    };
    while(f());
}

