#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)

char land[105][105];
int dx[4] = { 0, -1, 1, 0 }; int dy[4] = { -1, 0, 0, 1 };
int cnt;
char a;

void serch(int i, int j)
{

	if (land[i][j] == a)
	{
		land[i][j] = '0';
		REP(k, 4)
		{
			serch(i + dx[k], j + dy[k]);
		}
	}
}

int main()
{
	int h, w;
	while (1)
	{
		cnt = 0;
		cin >> h >> w; if (h == 0 && w == 0) return 0;
		REP(i, 100)REP(j, 100)
		{
			land[i][j] = '0';
		}
		REP(i, h)REP(j, w)
		{
			cin >> land[i][j];
		}
		REP(i, h)REP(j, w)
		{
			if (land[i][j] != '0')
			{

				cnt++;
				a = land[i][j];
				serch(i, j);
			}
		}
		cout << cnt << endl;
	}
}