#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class UnionFind {
    int n;
    vector<int> uni;
    int forest_size;
public:
    explicit UnionFind(int n) : n(n), uni(static_cast<u32>(n), -1), forest_size(n) {};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        forest_size--;
        return true;
    }
    int size(){ return forest_size; }
    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b) { return root(a) == root(b); }
};

int main() {
    int h, w;
    while(cin >> h >> w, h){
        vector<string> v(h);
        UnionFind uf(h*w);
        for (auto &&i : v) cin >> i;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if(i && v[i][j] == v[i-1][j])  uf.unite(i*w+j, (i-1)*w+j);
                if(j && v[i][j] == v[i][j-1]) uf.unite(i*w+j, i*w+j-1);
            }
        }
        cout << uf.size() << "\n";
    }
    return 0;
}
