#include <bits/stdc++.h>

#define rep_(v, f, l) for (int v = (f); v < (l); ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

struct UF {
    vector<int> data;
    UF(int size) : data(size, -1) {}
    bool merge(int a, int b){
        a = root(a), b = root(b);
        if (a != b){
            if (data[b] < data[a]) swap(a, b);
            data[a] += data[b];
            data[b] = a;
        }
        return a != b;
    }
    bool is_same(int a, int b){
        return root(a) == root(b);
    }
    int root(int a){
        return data[a] < 0 ? a : data[a] = root(data[a]);
    }
    int size(int a){
        return -data[root(a)];
    }
    int group_count(){
        int count = 0;
        rep(i, data.size()){
            if (data[i] < 0) count++;
        }
        return count;
    }
};

int main()
{
    vector<string> field;
    int h, w;
    while (h = in(), w = in(), w || h){
        rep(i, h){
            string s;
            cin >> s;
            field.push_back(s);
        }
        UF uf = UF(h * w);
        rep(i, h){
            rep(j, w){
                if (i + 1 < h && field[i][j] == field[i + 1][j]){
                    uf.merge(i * w + j, i * w + j + w);
                }
                if (j + 1 < w && field[i][j] == field[i][j + 1]){
                    uf.merge(i * w + j, i * w + j + 1);
                }
            }
        }
        printf("%d\n", uf.group_count());
    }
    return (0);
}