#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <functional>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;
constexpr double EPS = 1e-10;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int H, W;
    string s[100];
    function<void(int,int)> dfs = [&](int y, int x) {
        char c = s[y][x];
        s[y][x] = '.';
        REP(i,4) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(0 <= ny && ny < H && 0 <= nx && nx < W && s[ny][nx] == c) dfs(ny, nx);
        }
    };


    while(true) {
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        REP(i,H) cin >> s[i];
        
        int ans = 0;
        REP(i,H) REP(j,W) {
            if(s[i][j] != '.') {
                dfs(i, j);
                ++ans;
            }
        }

        cout << ans << '\n';
    }

    return 0;
}
