#include <iostream>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()


using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int H, W;
vector<string> field;
int dxy[5] = {-1, 0, 1, 0, -1};
void dfs(int y, int x, char c){
    field[y][x] = '.';

    for(int i=0; i<4; ++i){
        int ny = y + dxy[i], nx = x + dxy[i+1];

        if(ny>=0 && ny<H && nx >= 0 && nx < W && field[ny][nx] == c){
            dfs(ny, nx, c);
        }
    }
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    while(cin >> H >> W, H, W) {
        field.clear();
        rep(i, 0, H) {
            string s;
            cin >> s;
            field.push_back(s);
        }

        int cnt = 0;

        rep(i, 0, H) rep(j, 0, W) {
                if (field[i][j] != '.') {
                    cnt++;
                    dfs(i, j, field[i][j]);
                }
            }
        cout << cnt << endl;
    }
    return 0;
}
