#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int h, w;
char board[100][101];
int cluster[100][100];

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

void dps(int x, int y, int b, int n){
  if(x < 0  || y < 0 ) return;
  if(x >= w || y >= h) return;
  if(cluster[y][x] == 0 && board[y][x] == b){
    cluster[y][x] = n;
    REP(i,4) dps(x+dx[i], y+dy[i], b, n);
  }
}

int main(){
  while(scanf("%d%d ",&h,&w), h+w){
    int cnt = 0;
    REP(i,h) fgets(board[i], sizeof(board[i]), stdin);
    memset(cluster,0,sizeof(cluster));
    REP(i,h) REP(j,w)
      if(cluster[i][j] == 0)
        dps(j, i, board[i][j], ++cnt);
    cout << cnt << endl;
  }
  return 0;
}