#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
struct aa {
	int x;
	int y;
	int time;
};
class Compare {
public :
	bool operator()(const aa&l, const aa&r) {
		return l.time > r.time;
	}
};
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int main() {
	while (1) {
		int W, H; cin >> W >> H;
		if (!W)break;
		vector<vector<int>>field(H,vector<int>(W));
	
		for (int i = 0; i <H; ++i) {
			string st; cin >> st;
			for (int j = 0; j < W; ++j) {
				if (st[j] == '&')field[i][j] = 2;
				else if (st[j] == '.')field[i][j] = 1;
				else field[i][j] = 0;
			}
		}
		priority_queue<aa, vector<aa>, Compare>que;
		vector<vector<int>>memo(H, vector<int>(W, 1e8));
		for (int i = 0; i < H; ++i) {
			{
				int j = 0;
				que.push(aa{ j,i,0 });
				memo[i][j] = 0;

				j = W - 1;
				que.push(aa{ j,i,0 });
				memo[i][j] = 0;
			}
		}
		for (int j = 0; j < W; ++j) {
			{
				int i = 0;
				que.push(aa{ j,i,0 });
				memo[i][j] = 0;

				i= H - 1;
				que.push(aa{ j,i,0 });
				memo[i][j] = 0;
			}
		}
		int ans = -1;
		while (!que.empty()) {
			aa atop(que.top());
			if (field[atop.y][atop.x] == 2) {
				ans = atop.time;
				break;
			}
			que.pop();
			for (int way = 0; way < 4; ++way) {
				const int nextx = atop.x + dx[way];
				const int nexty = atop.y + dy[way];
				if (nextx < W&&nextx >= 0 && nexty >= 0 && nexty < H) {
					const int nexttime = atop.time + (field[nexty][nextx] && !field[atop.y][atop.x]);
					if (memo[nexty][nextx] > nexttime) {
						memo[nexty][nextx] = nexttime;
						que.push(aa{ nextx,nexty,nexttime });
					}
				}
			}
		}
		cout << ans << endl;
		
	}

	return 0;
}