#include "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct P
{
	int x, y;
	P(int x,int y):x(x),y(y){}
	P() :P(-1, -1) {}
};

string A[100];
int H, W;

void dfs(P nowp)
{
	static const int dx[] = { 1,0,-1,0 };
	static const int dy[] = { 0,1,0,-1 };

	char c = A[nowp.y][nowp.x];
	A[nowp.y][nowp.x] = '0';

	rep(i, 0, 4)
	{
		P nextp(nowp.x + dx[i], nowp.y + dy[i]);

		if (0 <= nextp.x&&nextp.x < W && 0 <= nextp.y&&nextp.y < H)
		{
			if (A[nextp.y][nextp.x] == c)
			{
				dfs(nextp);
			}
		}
	}
}

int solve()
{
	int ans = 0;
	rep(i, 0, H)rep(j, 0, W)
	{
		if (A[i][j] != '0')
		{
			ans++;
			dfs(P(j, i));
		}
	}
	return ans;
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	while (true)
	{
		cin >> H >> W;
		rep(i, 0, H)cin >> A[i];

		if (H == 0 && W == 0)
		{
			break;
		}
		cout << solve() << endl;
	}

	return 0;
}
