#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int solve(int h, int w, const auto& g) {
    using p = pair<int, int>;
    int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};
    auto v = make_v(h, w, false);

    auto in = [&](int i, int j) {
        return 0 <= i && i < h && 0<= j && j < w;
    };

    function<void(int, int)> rec = [&](int y, int x) {
        v[y][x] = true; 

        REP(i, 4) {
            int ny = y + dy[i], nx = x + dx[i];
            if (in(ny, nx) && !v[ny][nx] && g[y][x] == g[ny][nx]) {
                rec(ny, nx);
            }
        }
    };

    int cnt = 0;
    REP(i, h)REP(j, w) {
        if (!v[i][j]) {
            rec(i, j);
            cnt++;
        }
    }

    return cnt;
}

int main() {
    int h, w;
    while (cin >> h >> w, h && w) {
        auto g = make_v(h, w, '0');
        REP(i, h)REP(j, w) cin >> g[i][j];

        cout << solve(h, w, g) << endl;
    }

    return 0;
}

