#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;

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

string table[128];

void dfs(int r, int c, int R, int C, int ch) {
  if (!(0 <= r && r < R && 0 <= c && c < C)) return;
  if (table[r][c] != ch) return;
  table[r][c] = '.';
  dfs(r + 1, c, R, C, ch);
  dfs(r - 1, c, R, C, ch);
  dfs(r, c + 1, R, C, ch);
  dfs(r, c - 1, R, C, ch);
}

int main() {
  for (int R, C; cin >> R >> C, (R || C); ) {
      REP(r, R) cin >> table[r];
      int ans = 0;
      REP(r, R) REP(c, C) {
          if (table[r][c] != '.') {
              dfs(r, c, R, C, table[r][c]);
              ans++;
          }
      }
      cout << ans << endl;
  }
  return 0;
}