#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int h, w;
char field[100][100];
bool visit[100][100];
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

void dfs(int y, int x, char c) {
  visit[y][x] = true;
  REP(i, 4) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (0 <= ny && ny < h && 0 <= nx && nx < w && !visit[ny][nx] &&
        field[ny][nx] == c)
      dfs(ny, nx, c);
  }
}

int main() {
  while (true) {
    cin >> h >> w;
    if (h == 0 && w == 0) {
      return 0;
    }
    REP(i, h) REP(j, w) {
      cin >> field[i][j];
      visit[i][j] = false;
    }
    int ans = 0;
    REP(i, h) REP(j, w) {
      if (!visit[i][j]) {
        dfs(i, j, field[i][j]);
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
