#include <iostream>
#include <vector>

using namespace std;

vector<int> dx = { -1, 1, 0, 0 };
vector<int> dy = { 0, 0, -1, 1 };

void dfs(vector<vector<char>> &field, int x, int y) {
  char kind = field.at(x).at(y);
  // 訪問済みとマーク
  field.at(x).at(y) = 'x';
  // 四方を探索
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    // 同じ種類の樹木なら
    if (0 <= nx && nx < field.size() && 0 <= ny && ny < field.at(0).size() && field.at(nx).at(ny) == kind) {
      dfs(field, nx, ny);
    }
  }
}

void solve(int n, int m, vector<vector<char>> field)
{
  int count = 0;
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      // 訪問積みでなければ探索する
      if (field.at(i).at(j) != 'x') {
  		dfs(field, i, j);
        count++;
      }
    }
  }
  
  cout << count << endl;
}

int main()
{
  while (1)
  {
    int N, M;
    cin >> N >> M;

    if (N == 0 && M == 0)
      break;

    vector<vector<char>> field(N, vector<char>(M));

    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < M; j++)
      {
        cin >> field.at(i).at(j);
      }
    }

    solve(N, M, field);
  }
}

