//
//  main.cpp
//  aoj0118
//
//  Created by Wenfeng G on 7/31/19.
//  Copyright © 2019 Wenfeng G. All rights reserved.
//

#include <iostream>

int m, n, res;
char mat[102][102];

void dfs(char p, int x, int y) {
    if (x < 0 || x >= m || y < 0 || y >= n || mat[x][y] != p) {
        return;
    }
    mat[x][y] = '.';
    dfs(p, x-1, y);
    dfs(p, x+1, y);
    dfs(p, x, y-1);
    dfs(p, x, y+1);
}

void solve() {
    res = 0;
    for (int i = 0; i < m; i++) {
        std::cin >> mat[i];
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (mat[i][j] == '.') {
                continue;
            }
            dfs(mat[i][j], i, j);
            res++;
        }
    }
}

int main() {
    while (std::cin >> m >> n && m > 0 && n > 0) {
        solve();
        std::cout << res << std::endl;
    }
    return 0;
}

