//22
#include<iostream>
#include<queue>

using namespace std;

struct S{
  int x,y,t;
  bool operator<(S a)const{
    return t>a.t;
  }
};

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    char g[100][100];
    priority_queue<S> que;
    for(int y=0;y<m;y++){
      for(int x=0;x<n;x++){
	cin>>g[y][x];
	if(x==0||y==0||x==n-1||y==m-1){
	  S is={x,y,g[y][x]=='#'};
	  que.push(is);
	}
      }
    }
    bool mem[100][100]={{}};
    for(;;){
      S c=que.top();
      if(g[c.y][c.x]=='&')break;
      que.pop();
      if(mem[c.y][c.x]++)continue;
      for(int i=0;i<4;i++){
	int d[]={0,1,0,-1,0};
	int ny=c.y+d[i];
	int nx=c.x+d[i+1];
	if(0<=nx&&nx<n&&0<=ny&&ny<m){
	  S ns={nx,ny,c.t+((g[c.y][c.x]=='.')&&(g[ny][nx]=='#'))};
	  que.push(ns);
	}
      }
    }
    cout<<que.top().t<<endl;
  }
  return 0;
}