#include <iostream>
using namespace std;
int H,W; char**field; int res; 
bool flag=true;
void dfsApple(int h,int w){
  field[h][w]='$';
  if(field[h][w-1]=='@') dfsApple(h,w-1);
  if(field[h][w+1]=='@') dfsApple(h,w+1);
  if(field[h-1][w]=='@') dfsApple(h-1,w);
  if(field[h+1][w]=='@') dfsApple(h+1,w);
  return ;
  }
void dfsPsm(int h,int w){
  field[h][w]='%';
  if(field[h][w-1]=='#') dfsPsm(h,w-1);
  if(field[h][w+1]=='#') dfsPsm(h,w+1);
  if(field[h-1][w]=='#') dfsPsm(h-1,w);
  if(field[h+1][w]=='#') dfsPsm(h+1,w);
  return ;
  }
void dfsOrange(int h,int w){
  field[h][w]='^';
  if(field[h][w-1]=='*') dfsOrange(h,w-1);
  if(field[h][w+1]=='*') dfsOrange(h,w+1);
  if(field[h-1][w]=='*') dfsOrange(h-1,w);
  if(field[h+1][w]=='*') dfsOrange(h+1,w);
  return ;
  }
void solve(){
    cin >> H >> W;
    if(W==0) {flag=false; return ;}
    field = new char*[H + 2];
    for (int h = 0; h <= H + 1; h++) {
        field[h] = new char[W + 2];
    }
 for (int h = 1; h <= H; h++) {
  for (int w = 1; w <= W; w++) {
	  cin >> field[h][w]; 
   }
  }
 for(int w=0; w<=W+1; w++) {
   field[0][w]='.'; field[H+1][w]='.';
   }
 for(int h=0; h<=H+1; h++) {
   field[h][0]='.'; field[h][W+1]='.';
   }
for (int h = 1; h <= H; h++) {
 for (int w = 1; w <= W; w++) {
  if(field[h][w]=='@') {
        dfsApple(h,w); res++;
  }
  if(field[h][w]=='#') {
        dfsPsm(h,w); res++;
  }
  if(field[h][w]=='*') {
        dfsOrange(h,w); res++;
  }
 }
}
  cout<<res<<endl;
  return ;
  }
int main() {
   while(flag){
       res=0; solve();
       }
     return 0;
}