#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

void destroy ( vector<string>& field, int i, int j, int symbol ) {
  if( field[ i ][ j ] == symbol ) {
    int symbol = field[ i ][ j ];
    field[ i ][ j ] = '-';
    destroy( field, i - 1, j,     symbol );
    destroy( field, i + 1, j,     symbol );
    destroy( field, i    , j - 1, symbol );
    destroy( field, i    , j + 1, symbol );
  }
}

int search ( vector<string>& field, int i, int j ) {
  static int counter = 0;
  if( i == 1 && j == 1 ) { counter = 0; }
  if( field[ i ][ j ] == '-' ) { return counter; }
  counter++;
  int symbol = field[ i ][ j ];
  field[ i ][ j ] = '-';
  destroy( field, i - 1, j,     symbol );
  destroy( field, i + 1, j,     symbol );
  destroy( field, i    , j - 1, symbol );
  destroy( field, i    , j + 1, symbol );
  return counter;
}


int main() {
  while( 1 ) {
    int h, w;
    cin >> h >> w;
    if( !( h | w ) ) { return EXIT_SUCCESS; }
    vector<string> field( h + 2 );
    
    field[ 0 ] = "";
    field[ h + 1 ] = "";
    for( int j = 0; j <= w + 1; j++ ) {
      field[ 0 ] += "-";
      field[ h + 1 ] += "-";
    }
    for( int i = 1; i <= h ; i++ ) {
      cin >> field[ i ];
      field[ i ] = "-" + field[ i ] + "-";
    }
    
    int n;
    for( int i = 1; i <= h; i++ ) {
      for( int j = 1; j <= w; j++ ) {
        n = search( field, i, j );
      }
    }
    
    cout << n << endl;
  }
}