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

#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))

const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};

int W, H;
char B[111][111];

void dfs(int y, int x, char c) {
   B[y][x] = '-';
   rep (i, 4) {
      int nx = x + dx[i] , ny = y + dy[i];
      if (nx >= 0 && nx < W && ny >= 0 && ny < H && B[ny][nx] == c) dfs(ny, nx, c);
   }
}

int main() {
   while (cin >> H >> W, W) {
      rep (i, H) cin >> B[i];
      int cnt = 0;
      rep (i, H) rep (j, W) if (B[i][j]!='-') cnt++, dfs(i, j, B[i][j]);
      cout << cnt << endl;
   }
   
   return 0;
}
