#include <iostream>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;

typedef pair<int, int> P;
typedef pair<P, int> Q;

int main() {
	int n, m;
	while (cin >> m >> n) {
		if (n == 0 && m == 0) {
			break;
		}
		vector< vector<char> > c(n, vector<char>(m));
		vector< vector<int> > d(n, vector<int>(m, 1000));
		int si, sj;
		si = sj = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cin >> c[i][j];
				if (c[i][j] == '&') {
					si = i;
					sj = j;
					c[si][sj] = '.';
				}
			}
		}
		d[si][sj] = 0;
		queue<Q> q;
		int di[] = {1, 0, -1, 0};
		int dj[] = {0, 1, 0, -1};
		q.push(Q(P(si, sj), 0));
		while (!q.empty()) {
			Q qq = q.front();
			q.pop();
			P pp = qq.first;
			for (int i = 0; i < 4; i++) {
				if (pp.first+di[i] >= 0 && pp.first+di[i] < n && pp.second+dj[i] >= 0 && pp.second+dj[i] < m) {
					int aa = qq.second;
					if (c[pp.first][pp.second] == '.' && c[pp.first+di[i]][pp.second+dj[i]] == '#') {
						aa++;
					}
					if (d[pp.first+di[i]][pp.second+dj[i]] > aa) {
						d[pp.first+di[i]][pp.second+dj[i]] = aa;
						q.push(Q(P(pp.first+di[i], pp.second+dj[i]), aa));
					}
				}
			}
		}
/*
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << d[i][j];
			}
			cout << endl;
		}
		*/
		int MIN = 1000;
		for (int i = 0; i < n; i++) {
			MIN = min(MIN, min(d[i][0], d[i][m-1]));
		}
		for (int i = 0; i < m; i++) {
			MIN = min(MIN, min(d[0][i], d[n-1][i]));
		}
		cout << MIN << endl;
	}
	return 0;
}