#include <iostream>
#include <queue>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)
#define GROUND '.'
#define MOAT '#'

using namespace std;

const int INF = 1 << 30;
const int dir[][2] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };

char M[105][105];
int  v[105][105];
int n, m;	// n: ¼Ì m: ìkÌ 

bool dfs (int cr, int cc, int color, char target )
{
	v[cr][cc] = color;
	if (cr == 0 || cr == m+1 || cc == 0 || cc == n+1 ){
		return true;
	} // end if

	rep (k, 4 ){
		int nr = cr + dir[k][0], nc = cc + dir[k][1];
		if ((M[nr][nc] == target && v[nr][nc] == INF ) || v[nr][nc] < color ){
			return dfs (nr, nc, color, target );
		} // end if
	} // end while

	return false;
}

void init_map ()
{
	rep (i, m+2 ){
		rep (j, n+2 ){
			M[i][j] = GROUND;
			v[i][j] = INF;
		} // end rep
	} // end rep
}

int main()
{
	while (cin >> n >> m && n && m ){
		int sr, sc;
		init_map ();
		for (int i = 1; i <= m; i++ ){
			for (int j = 1; j <= n; j++ ){
				cin >> M[i][j];
				if (M[i][j] == '&' ){
					sr = i, sc = j;
					M[i][j] = GROUND;
				} // end if
			} // end for
		} // end for
		int res = 0;
		while (1){
			if (dfs (sr, sc, res, GROUND ) ){
				break;
			} // end if
			res++;
			if (dfs (sr, sc, res, MOAT ) ){
				break;
			} // end if
			res++;
		} // end while
		cout << res/2 << endl;
	} // end loop
		
	return 0;
}