#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);
		}
		bool update=true;
		int xx[]={1,-1,0,0},yy[]={0,0,1,-1};
		int k;
		while(update){
			update=false;
			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					if(i==0||i==h-1||j==0||j==w-1){
						if(res[i][j]>=2){
							res[i][j]=m[i][j]=='#'?1:0;
							update=true;
						}
					}else if(m[i][j]=='#'){
						for(k=0;k<4;k++){
							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{
						for(k=0;k<4;k++){
							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;
}