#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

char field[100][100];
int H, W;

void dfs(int x, int y) {
  if(field[x][y] == '#') {
    field[x][y] = '0';
    for(int dx = -1 ; dx <= 1 ; dx++) {
      int nx = x + dx;
      if(0 <= nx && nx < H && field[nx][y] == '#') dfs(nx, y);
    }
    for(int dy = -1 ; dy <= 1 ; dy++) {
      int ny = y + dy;
      if(0 <= ny && ny < W && field[x][ny] == '#') dfs(x, ny);
    }
  }
  else if(field[x][y] == '*') {
    field[x][y] = '0';
    for(int dx = -1 ; dx <= 1 ; dx++) {
      int nx = x + dx;
      if(0 <= nx && nx < H && field[nx][y] == '*') dfs(nx, y);
    }
    for(int dy = -1 ; dy <= 1 ; dy++) {
      int ny = y + dy;
      if(0 <= ny && ny < W && field[x][ny] == '*') dfs(x, ny);
    }
  }
  else if(field[x][y] == '@') {
    field[x][y] = '0';
    for(int dx = -1 ; dx <= 1 ; dx++) {
      int nx = x + dx;
      if(0 <= nx && nx < H && field[nx][y] == '@') dfs(nx, y);
    }
    for(int dy = -1 ; dy <= 1 ; dy++) {
      int ny = y + dy;
      if(0 <= ny && ny < W && field[x][ny] == '@') dfs(x, ny);
    }
  }
}

int main() {
  int cnt;
  while(cin >> H >> W, H && W) {
    cnt = 0;
    memset(field, '0', sizeof(field));
    for(int i = 0 ; i < H ; i++) 
      for(int j = 0 ; j < W ; j++) cin >> field[i][j];
    
    for(int i = 0 ; i < H ; i++) {
      for(int j = 0 ; j < W ; j++) {
	if(field[i][j] != '0') {
	  dfs(i, j);
	  cnt++;
	}
      }
    }
    cout << cnt << endl;
  }
  return 0;
}