#include<bits/stdc++.h>
using namespace std;

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int h, w;
vector< vector<char> > v;

void dfs(int y, int x, char c){
    v[y][x] = '.';
    rep(i, 4){
        int ny = y + dy4[i], nx = x + dx4[i];
        if(v[ny][nx] == c){
            dfs(ny, nx, c);
        }
    }
    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    while(cin >> h >> w, h){
        v.resize(h + 2);
        rep(i, h + 2){
            v[i].clear();
            v[i].resize(w + 2, '.');
        }
        REP(i, 1, h + 1){
            REP(j, 1, w + 1){
                cin >> v[i][j];
            }
        }
        int ans = 0;
        REP(i, 1, h + 1){
            REP(j, 1, w + 1){
                if(v[i][j] != '.'){
                    ++ans;
                    dfs(i, j, v[i][j]);
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}
