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

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

int h, w;
vector<string> s;
vector<vector<bool>> visited;

void dfs(int y, int x, char c) {
  if(y < 0 || y >= h || x < 0 || x >= w || visited[y][x] || c != s[y][x]) return;
  visited[y][x] = true;

  for(int i = 0; i < 4; ++i) dfs(y + dy[i], x + dx[i], c);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while(cin >> h >> w, h != 0 && w != 0) {
    s = vector<string>(h);
    visited = vector<vector<bool>>(h, vector<bool>(w, false));
    for(int i = 0; i < h; ++i) cin >> s[i];

    int cnt = 0;
    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
        if(!visited[i][j]) {
          dfs(i, j, s[i][j]);
          cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
}
