#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

vector<string> m;
vector<vint> res;

int main() {
	int h,w;
	while(cin>>w>>h,h){
		m.clear();
		res.clear();
		int i,j;
		vint buf;
		for(i=0;i<w;i++)buf.push_back(100100100);
		for(i=0;i<h;i++){
			string str;
			cin>>str;
			m.push_back(str);
			res.push_back(buf);
		}
		for(i=0;i<w;i++)res[0][i]=res[h-1][i]=0;
		for(i=0;i<h;i++)res[i][0]=res[i][w-1]=0;
		bool update=true;
		int xx[]={1,-1,0,0},yy[]={0,0,1,-1};
		int k;
		while(update){
			update=false;
			for(i=1;i<h-1;i++){
				for(j=1;j<w-1;j++){
					for(k=0;k<4;k++){
						if(m[i+yy[k]][j+xx[k]]=='#'&&m[i][j]!='#'){
							if(res[i+yy[k]][j+xx[k]]+1<res[i][j]){
								res[i][j]=res[i+yy[k]][j+xx[k]]+1;
								update=true;
							}
						}else{
							if(res[i+yy[k]][j+xx[k]]<res[i][j]){
								res[i][j]=res[i+yy[k]][j+xx[k]];
								update=true;
							}
						}
					}
				}
			}
		}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
//cout<<res[i][j]<<" ";
				if(m[i][j]=='&'){
					cout<<res[i][j]<<endl;
				}
			}
//cout<<endl;
		}
	}
	return 0;
}