#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int a[100][100],p,w,h;
int fn(int x,int y){
  if(0){
  }else if(a[x][y]==-2){
    a[x][y]=p+1;
  }else if(a[x][y]==-1){
    if(x==0||x==w-1||y==0||y==h-1)
      return 1;
    a[x][y]=p;
    if(fn(x-1,y)||fn(x,y-1)||fn(x+1,y)||fn(x,y+1))
      return 1;
  }
  return 0;
}
int fm(int x,int y){
  if(0){
  }else if(a[x][y]==-2){
    if(x==0||x==w-1||y==0||y==h-1)
      return 1;
    a[x][y]=p;
    if(fm(x-1,y)||fm(x,y-1)||fm(x+1,y)||fm(x,y+1))
      return 1;
  }
  return 0;
}
int main(){
  int i,j,k;
  char c;
  while(cin>>w>>h&&w+h){
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	cin>>c;
	if(0){
	}else if(c=='#'){
	  a[j][i]=-2;
	}else if(c=='.'){
	  a[j][i]=-1;
	}else if(c=='&'){
	  a[j][i]=0;
	}
      }
    }
    for(p=0;;){
      for(j=0;j<h;j++){
	for(k=0;k<w;k++){
	  if(a[k][j]==p){
	    if(k==0||k==w-1||j==0||j==h-1)
	      break;
	    if(fn(k-1,j)||fn(k,j-1)||fn(k+1,j)||fn(k,j+1))
	      break;
	  }
	}
	if(k!=w)
	  break;
      }
      if(j!=h)
	break;
      p++;
      for(j=0;j<h;j++){
	for(k=0;k<w;k++){
	  if(a[k][j]==p){
	    if(k==0||k==w-1||j==0||j==h-1)
	      break;
	    if(fm(k-1,j)||fm(k,j-1)||fm(k+1,j)||fm(k,j+1))
	      break;
	  }
	}
	if(k!=w)
	  break;
      }
      if(j!=h)
	break;
    }
    cout<<p<<endl;
  }
  return 0;
}