#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

int n, m;
int cnt = 0;

vector<vector<char> > hata;

void dfs(int x, int y, char c) {
  hata[y][x] = 0;

  for(int k = -1; k <= 1; k++ ) {
    int nx = x+k;
    int ny = y+k;

    if(nx >= 0 && nx < m && hata[y][nx] == c) dfs(nx, y, c);
    if(ny >= 0 && ny < n && hata[ny][x] == c) dfs(x, ny, c);
  }
  return;
}
    
int main(void)
{
  cin >> n >> m;
  cnt = 0;

  while(!(n == 0 && m == 0)){
    hata.clear();
    for(int i = 0; i < n; i++) {
      hata.push_back(std::vector<char>());
      for(int j = 0; j < m; j++){
        char a;
        std::cin >> a;
        hata[i].push_back(a);
      }
    }
    for(int i = 0; i < n; i++ ) {
      for(int j = 0; j < m; j++ ) {
        if(hata[i][j] != 0) {
          dfs(j, i, hata[i][j]);
          cnt++;
        }
      }
    }
    cout << cnt << endl;
    cin >> m >> n;
  }
  return 0;
}