#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxH = 100, kMaxW = 100;

int H, W;
char field[kMaxH][kMaxW];
int ans;

bool checked[kMaxH][kMaxW];

void Dfs(int x, int y) {
  checked[x][y] = true;

  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  REP(i, 4) {
    int nx = x+dx[i];
    int ny = y+dy[i];
    if (0 <= nx && nx < H && 0 <= ny && ny < W) {
      if (!checked[nx][ny] && field[nx][ny] == field[x][y]) { Dfs(nx, ny); }
    }
  }

  return;
}

bool Solve() {
  cin >> H >> W;
  if (H == 0) { return false; }
  REP(i, H) { cin >> field[i]; }
  ans = 0;
  fill(checked[0], checked[H], false);

  REP(i, H) {
    REP(j, W) {
      if (!checked[i][j]) {
        Dfs(i, j);
        ++ans;
      }
    }
  }

  cout << ans << endl;
  return true;
}

int main() {
  while (Solve()) { ; }

  return 0;
}

