Import Java.util.Scanner;
public class Main1241 {
public static void Main (string[] args) {
Scanner cin=new Scanner (system.in);
while (Cin.hasnext ()) {
int N=cin.nextint ();
int M=cin.nextint ();
if (n==0) {
Break
}
Plot [][]plots=new Plot[n][m];
for (int i=0;i<n;i++) {
String Str=cin.next ();
for (int j=0;j<m;j++) {
Plots[i][j]=new plot ();
Plots[i][j].x=i;
Plots[i][j].y=j;
Plots[i][j].c=str.charat (j);
}
}
int count=0;
print (plots);
for (int i=0;i<n;i++) {
for (int j=0;j<m;j++) {
if (plots[i][j].c== ' @ ' &&!plots[i][j].isvisable) {
Plotqueue queue=new plotqueue ();
Queue.in (Plots[i][j]);
BFS (Plots,queue);
count++;
}
}
}
System.out.println (count);
}
}
final static int [][]dir={{-1,0},{0,-1},{-1,-1},{0,1},{1,0},{1,1},{1,-1},{-1,1}};
private static void BFs (plot[][] plots, Plotqueue queue) {
int px;
int py;
int n=plots.length;
int m=plots[0].length;
while (!queue.isempty ()) {
Plot plots=queue.out ();
for (int i=0;i<8;i++) {
PX=PLOTS.X+DIR[I][0];
PY=PLOTS.Y+DIR[I][1];
if (px>=0&&px<n&&py>=0&&py<m&&plots[px][py].c== ' @ ' &&!plots[ px][py].isvisable) {
Plots[px][py].isvisable=true;
Queue.in (Plots[px][py]);
}
}
}
}
private static void print (plot[][] plots) {
for (int i=0;i<plots.length;i++) {
for (int j=0;j<plots[i].length;j++) {
System.out.print (PLOTS[I][J].C);
}
System.out.println ();
}
}
}
Class plot{
int x;
int y;
char c;
Boolean isvisable=false;
}
Class plotqueue{
Plot []plot;
int end;
final int frist=0;
Public Plotqueue () {
Plot=new plot[100];
}
public void in (plot p) {
Plot[end]=p;
end++;
}
Public plot out () {
Plot p;
if (end<=0) {
return null;
}
else{
P=plot[frist];
for (int i=0;i<end;i++) {
PLOT[I]=PLOT[I+1];
}
end--;
}
return p;
}
public Boolean IsEmpty () {
if (end<=0) {
return true;
}
return false;
}
}
HDU1241 (BFS) JAVA