#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s[100];
char c[]={'#','.'};
int a,b,p1,p2,dx[]={1,-1,0,0},dy[]={0,0-1,1};
int dfs(int y,int x){
  int sum=0;
  s[y][x]=c[p1];
  if(y==0||x==0||y==a-1||x==b-1)return 1;
  r(i,4)if(x+dx[i]>=0&&dx[i]+x<b&&y+dy[i]>=0&&dy[i]+y<a)
    if(s[y+dy[i]][x+dx[i]]==c[p2])
      sum=dfs(y+dy[i],x+dx[i]);
  return sum;
}
main(){
  while(cin>>b>>a,a){
    r(i,a)cin>>s[i];
    int su=0;
    r(i,a)r(j,b){
      if(s[i][j]=='&'){
        p1=0;p2=1;
        if(dfs(i,j))goto L;
        p1=1;p2=0;
        su++;
        if(dfs(i,j))goto L;
      }
    }
    L:cout<<su<<endl;
  }
}