#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;

int H,W;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
vector<vector<int> > maze;

bool range(int i, int j){
  return (i>=0 && i<W && j>=0 && j<H && maze[i][j] != 0);
}

void dfs(int i, int j){
  int l,check = maze[i][j];
  maze[i][j] = 0;
  REP(l,4){
    if(range(i+dx[l],j+dy[l]) && check == maze[i+dx[l]][j+dy[l]]) dfs(i+dx[l],j+dy[l]);
  }
}

int main(void){
  int i,j,count;
  while(true){
    count = 0;
    cin >> H >> W;
    if(H*W==0) break;
    maze = vector<vector<int> >(W,vector<int>(H));
    REP(j,H)REP(i,W){
      char x;
      cin >> x;
      if(x=='#') maze[i][j] = 1;
      else if(x=='@') maze[i][j] = 2;
      else maze[i][j] = 3;
    }
    REP(j,H)REP(i,W){
      if(range(i,j)){
        dfs(i,j);
        count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}

