#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<functional>
#include<list>
#include<unordered_map>
#include<map>
#define P pair<int,int>
using namespace std;

int a, b;
string c[102];
int dx[4] = { -1,0,0,1 }, dy[4] = { 0,-1,1,0 };
vector<P>V;
int main() {
	while (cin >> b >> a, a | b) {
		string f;
		for (int g = 0; g < b + 2; g++)f += ".";
		c[0] = c[a + 1] = f;
		for (int d = 0; d < a; d++) {
			string e; cin >> e;
			c[d + 1] = "." + e + ".";
		}
		a+=2; b+=2;
		for (int I = 0;; I++) {
			queue<P>Q;
			Q.push(P(0,0));
			c[0][0] = 0;
			V.push_back(P(0,0));
			while (Q.size()) {
				P t = Q.front(); Q.pop();
				for (int i = 0; i < 4; i++) {
					int x = t.first + dx[i], y = t.second + dy[i];
					if (x >= 0 && x < a&&y >= 0 && y < b) {
						if (c[x][y] == '.') {
							V.push_back(P(x, y));
							c[x][y] = 0;
							Q.push(P(x,y));
						}
						else if (c[x][y] == '#') {
							V.push_back(P(x,y));
						}
						else if (c[x][y] == '&') {
							cout << I << endl;
							goto l;
						}
					}
				}
			}
			for (P o : V) {
				c[o.first][o.second] = '.';
			}
			V.clear();
		}
	l:;
	}
}