#include"stdio.h"
#include"string.h"
int map[25][25],des[25][25],n,m,sx,sy;
void DFS(int y,int x)
{
if(map[y][x]=='#'||des[y][x]||y>n||x>m)
return ;
des[y][x]=1;
DFS(y-1,x);
DFS(y+1,x);
DFS(y,x-1);
DFS(y,x+1);
}
int main()
{
while(scanf("%d%d*c",&m,&n),n||m)
{
for(int i=0;i<25;++i)
for(int j=0;j<25;j++)
map[i][j]='#',des[i][j]=0;
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='0')
sy=i,sx=j;
}
getchar();
}
DFS(sy,sx);
int c=0,i,j;
for(i=1;i<=n;++i)
for(j=1;j<=m;++j)
if(des[i][j])
++c;
printf("%d\n",c);
}
return 0;
}