#include <iostream>
#include <cstring>
using namespace std;
int w, h;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
char *hatake;

void dfs(int x, int y, char c);

int main() {
  char *buf;
  int a;
  char c;

  while (1) {
    cin >> w >> h;
    if (!w && !h) break;

    hatake = new char[w*h];
    buf = new char[w+1];
    for (int i=0; i<h; i++) {
      cin >> buf;
      memcpy(&hatake[i*w], buf, sizeof(char)*w);
    }

    a = 0;
    for (int i=0; i<h; i++) {
      for (int j=0; j<w; j++) {
        if (hatake[i*w+j]!='.') {
          c = hatake[i*w+j];
          hatake[i*w+j]='.';
          dfs(j,i,c);
          a++;
        }
      }
    }
    cout << a << endl;

    delete [] hatake;
    delete [] buf;
  }
  return 0;
}

void dfs(int x, int y, char c) {
  int nx, ny;
  for (int i=0; i<4; i++) {
    nx = x + dx[i];
    ny = y + dy[i];
    if (nx>=0 && nx<w && ny>=0 && ny<w && hatake[ny*w+nx]==c) {
      hatake[ny*w+nx] = '.';
      dfs(nx, ny, c);
    }
  }
}