import std.stdio : readln, writeln;
import std.array : split;
import std.conv : to;
import std.typecons;
import std.algorithm : map;
import std.string : chomp;

char[Tuple!(int, int)] field;
int W, H;

void dfs(int x, int y, char f) {
  field[tuple(x, y)] = '.';
  foreach (dx; [-1, 1]) {
    int nx = x + dx;
    if (0 <= nx && nx < W
        && field[tuple(nx, y)] == f) dfs(nx, y, f);
  }
  foreach (dy; [-1, 1]) {
    int ny = y + dy;
    if (0 <= ny && ny < H
        && field[tuple(x, ny)] == f) dfs(x, ny, f);
  }
}

void main() {
  while (1) {
    auto input = map!(to!int)(split(chomp(readln()))[0 .. 2]);
    H = input[0], W = input[1];
    if (W == 0 && H == 0) break;

    field = field.init;
    foreach (int y; 0 .. H)
      foreach (int x, char f; readln()[0 .. W])
        field[tuple(x, y)] = f;

    int res = 0;
    foreach (xy; field.keys) {
      char f = field[tuple(xy[0], xy[1])];
      switch (f) {
      case '#': case '@': case '*':
        dfs(xy[0], xy[1], f);
        res++;
        break;
      default:
        break;
      }
    }
    writeln(res);
  }
}