import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;


void main()
{
	while (1) {
		auto x = readln.chomp.split.map!(to!int);
		if (!x[0]) break;
		auto area = new char[][](x[0], x[1]);
		foreach (i; 0..x[0]) {
			area[i] = readln.chomp.map!(to!char).array;
		}

		int cnt;

		void solve(int i, int j, char type) {
			area[i][j] = '.';
			foreach (a; iota(-1, 2, 2)) {
				if (i+a >= 0 && i+a < x[0]) {
					if (area[i+a][j] == type) solve(i+a, j, type);
				}
				if (j+a >= 0 && j+a < x[1]) {
					if (area[i][j+a] == type) solve(i, j+a, type);
				}
			}
		}

		foreach (i; 0..x[0]) {
			foreach (j; 0..x[1]) {
				if (area[i][j] == '.') continue;
				cnt++;
				solve(i, j, area[i][j]);
			}
		}
		cnt.writeln;
	}
}