#include <bits/stdc++.h>
using namespace std;
 
int h, w;
const int MAX = 110;
char C[MAX][MAX];
bool seen[MAX][MAX];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
 
struct UnionFind{
    vector<int> par;
    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++){
            par[i] = -1;
        }
    }
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        else{
            if(par[rx] == par[ry]){
                if(rx > ry) swap(rx, ry);
            }else if(par[rx] > par[ry]) swap(rx, ry);
            par[rx] += par[ry];
            par[ry] = rx;
       }
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    void check(){
        for(auto x : par){
            cout << x << " ";
        }
        cout << endl;
    }
};
 
void dfs(int x, int y, char c, UnionFind &uf){ 
    seen[x][y] = true;
    for(int i = 0; i < 4; i++){
        int nx, ny;
        nx = dx[i] + x;
        ny = dy[i] + y;
        if(nx < 0 or ny < 0 or nx >= h or ny >= w) continue;
        if(C[nx][ny] != c or seen[nx][ny]) continue;
        uf.unite(x * w + y, nx * w + ny);
        dfs(nx, ny, c, uf);
    }
    return;
}
 
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    while(true){
        cin >> h >> w;
        if(h == 0 and w == 0){
            return 0;
        }

        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                seen[i][j] = false;
            }
        }

        UnionFind uf(h * w);
    
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> C[i][j];
            }
        }
    
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                dfs(i, j, C[i][j], uf);
            }
        }
    
        set<int> st;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                st.insert(uf.root(i * w + j));
            }
        }
 
        cout << st.size() << endl;
    }

    return 0;
}
