#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <cstdio>
#include <cmath>

#define REP(i, b, n) for(int i=(b); i<(n); ++i)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define foreach(it, v) for(typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int h, w;
bool inRange(int a, int x, int b){return a <= x && x < b;}
void dfs(vector<string> &in, int i, int j){
    char c = in[i][j]; in[i][j] = '.';
    rep(d, 4) if(inRange(0, i+dx[d], h) && inRange(0, j+dy[d], w))
        if(in[i+dx[d]][j+dy[d]] == c) dfs(in, i+dx[d], j+dy[d]);
}
void solve(vector<string> &in){
    int res = 0;
    rep(i, h) rep(j, w) if(in[i][j] != '.') dfs(in, i, j), ++res;
    cout << res << endl;
}
int main(void){
    while(cin >> h >> w, h|w){
        vector<string> in(h);
        rep(i, h) cin >> in[i];
        solve(in);
    }
    return 0;
}