#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

struct xydata {
    int x; int y;
};

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

int h, w;
vector< vector<char> > smap(110, vector<char>(110, '.'));

void bfs(vector< vector<char> > &xmap, char key, int xx, int yy) {
    queue<xydata> que;
    xydata indata; indata.x = xx; indata.y = yy;
    que.push(indata);
    xmap.at(yy).at(xx) = 'X';
    while(!que.empty()) {
        xydata now = que.front(); que.pop();
        for(int i = 0; i < 4; ++i) {
            int nx = now.x+dx[i]; int ny = now.y+dy[i];
            if(nx >= 0 && nx < w && ny >= 0 && ny < h) {
                if(xmap.at(ny).at(nx) == key) {
                    xmap.at(ny).at(nx) = 'X';
                    xydata next; next.x = nx; next.y = ny;
                    que.push(next);
                }
            }
        }
    }
}

int main() {
    while(1) {
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                cin >> smap.at(i).at(j);
            }
        }

        int cnt = 0;
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                if(smap.at(i).at(j) != 'X') {
                    cnt++;
                    bfs(smap, smap.at(i).at(j), j, i);
                }
            }
        }

        cout << cnt << endl;
    }
}
