#include <iostream>

#define rep(i, a, b) for(int i = a; i < b; i ++) 

using namespace std;

int h, w;
char m[100][100];
int m2[100][100] = {0};
void exp(int x, int y, char f) {
  if(x < 0 || w <= x || y < 0 || h <= y) return;
  if(m[x][y] != f || m2[x][y] == 1) return;

  m2[x][y] = 1;
  exp(x-1, y, f);
  exp(x+1, y, f);
  exp(x, y-1, f);
  exp(x, y+1, f);

  return;
}

int main() {
  while(cin >> h >> w, h) {
    rep(i, 0, h) {
      rep(j, 0, w) {
	cin >> m[j][i];
	m2[j][i] = 0;
      }
    }

    int ans = 0;
    rep(i, 0, h) {
      rep(j, 0, w) {
	if(m2[j][i] == 0) {
	  exp(j, i, m[j][i]);	  
	  ans ++;
	}
      }
    }

    cout << ans << endl;
  }	
  return 0;
}