#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>
#include <stack>
#include <set>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
    return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
    os<<'[';
    rep(i,a.size()) os<<(i?" ":"")<<a[i];
    return os<<']';
}


int H, W;
char map[110][110];
bool visited[110][110];

void go(int x, int y) {
	visited[y][x] = true;
	static int dx[4] = {1, 0, -1, 0};
	static int dy[4] = {0, 1, 0, -1};
	rep(d, 4) {
		int tx = x + dx[d];
		int ty = y + dy[d];
		if (tx < 0 || tx >= W || ty < 0 || ty >= H) continue;
		if (visited[ty][tx]) continue;
		if (map[y][x] != map[ty][tx]) continue;
		go(tx, ty);
	}
}

int main() {
	for(; cin >> H >> W, (H|W) != 0; ) {
		rep(i, H) rep(j, W) {
			cin >> map[i][j];
		}
		int ans = 0;
		memset(visited, false, sizeof(visited));
		rep(i, H) rep(j, W) {
			if (!visited[i][j]) {
				go(j, i);
				ans++;
			}
		}
		cout << ans << endl;
	}

	return 0;
}